Skip to content

Commit

Permalink
Merge pull request #1812 from France-ioi/crash-reporting-avoid-severa…
Browse files Browse the repository at this point in the history
…l-dialog

Crash reporting: avoid several dialog
  • Loading branch information
smadbe authored Oct 21, 2024
2 parents ee0a323 + f4812cf commit 2d3ae8d
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/app/utils/error-handling/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,39 @@ import { ChunkErrorService } from '../../services/chunk-error.service';
@Injectable()
export class AlgErrorHandler extends ErrorHandler {

private sentryErrorHandler = Sentry.createErrorHandler({
showDialog: true,
});
private isDialogOpen = false;
/**
* list of errors which have already been reported in this session so that we do not report the same one several times
*/
private reportedErrors: string[] = [];

constructor(private chunkErrorService: ChunkErrorService) {
super();
}

handleError(err: any): void {
if (this.isChunkLoadingError(err)) {
this.chunkErrorService.emitError();
return;
}
const error = convertToError(err);
const eventId = Sentry.captureException(error);

if (!this.isDialogOpen && !this.reportedErrors.includes(error.toString())) {
this.isDialogOpen = true;
this.reportedErrors.push(error.toString());
Sentry.showReportDialog({ eventId, onClose: () => this.isDialogOpen = false });
}
}

isChunkLoadingError(err: any): boolean {
const chunkErrormessages = [
'Loading chunk [a-z_\\d]+ failed', // older ?
'Failed to fetch dynamically imported module', // chrome
'error loading dynamically imported module', // firefox
'Importing a module script failed', // safari
];
if (new RegExp(chunkErrormessages.map(m => `(${m})`).join('|')).test(convertToError(err).message)) {
this.chunkErrorService.emitError();
return;
}
this.sentryErrorHandler.handleError(convertToError(err));
return new RegExp(chunkErrormessages.map(m => `(${m})`).join('|')).test(convertToError(err).message);
}

}

0 comments on commit 2d3ae8d

Please sign in to comment.