diff --git a/frontend/src/app/core/errors/sentry/sentry-reporter.ts b/frontend/src/app/core/errors/sentry/sentry-reporter.ts index df24f6d3ee..fd8b8b4e98 100644 --- a/frontend/src/app/core/errors/sentry/sentry-reporter.ts +++ b/frontend/src/app/core/errors/sentry/sentry-reporter.ts @@ -36,6 +36,7 @@ import { environment } from '../../../../environments/environment'; import { EventHint } from '@sentry/angular'; import { HttpErrorResponse } from '@angular/common/http'; import { debugLog } from 'core-app/shared/helpers/debug_output'; +import { HalError } from 'core-app/features/hal/services/hal-error'; export type ScopeCallback = (scope:Scope) => void; export type MessageSeverity = 'fatal'|'error'|'warning'|'log'|'info'|'debug'; @@ -103,10 +104,10 @@ export class SentryReporter implements ErrorReporter { switch (samplingContext.transactionContext.op) { case 'op': case 'navigation': - // Trace 1% of page loads and navigation events + // Trace 1% of page loads and navigation events return Math.min(0.01 * traceFactor, 1.0); default: - // Trace 0.1% of requests + // Trace 0.1% of requests return Math.min(0.001 * traceFactor, 1.0); } }, @@ -215,8 +216,13 @@ export class SentryReporter implements ErrorReporter { // avoid duplicate requests on thrown angular errors, they // are handled by the hal error handler // https://github.com/getsentry/sentry-javascript/issues/2532#issuecomment-875428325 - if (hint?.originalException instanceof HttpErrorResponse) { - return null; + const exception = hint?.originalException; + if (exception instanceof HttpErrorResponse) { + return SentryReporter.filterHttpError(event, exception); + } + + if (exception instanceof HalError) { + return SentryReporter.filterHttpError(event, exception.httpError); } const unsupportedBrowser = document.body.classList.contains('-unsupported-browser'); @@ -227,4 +233,18 @@ export class SentryReporter implements ErrorReporter { return event; } + + /** + * Filter http errors before sending to sentry. For now, we only want 5xx+ errors + * @param event + * @param exception + * @private + */ + private static filterHttpError(event:SentryEvent, exception:HttpErrorResponse):SentryEvent|null { + if (exception.status >= 500) { + return event; + } + + return null; + } } diff --git a/frontend/src/app/features/hal/services/hal-aware-error-handler.ts b/frontend/src/app/features/hal/services/hal-aware-error-handler.ts index ac1d788a38..b805797fa6 100644 --- a/frontend/src/app/features/hal/services/hal-aware-error-handler.ts +++ b/frontend/src/app/features/hal/services/hal-aware-error-handler.ts @@ -35,7 +35,7 @@ export class HalAwareErrorHandler extends ErrorHandler { if (error instanceof HalError) { console.error('Returned HTTP HAL error resource %O', error.message); message = error.httpError?.status >= 500 ? `${message} ${error.message}` : error.message; - HalAwareErrorHandler.captureHttpError(error.httpError); + HalAwareErrorHandler.captureError(error.httpError); } else if (error instanceof ErrorResource) { console.error('Returned error resource %O', error); message += ` ${error.errorMessages.join('\n')}`; @@ -43,9 +43,9 @@ export class HalAwareErrorHandler extends ErrorHandler { console.error('Returned hal resource %O', error); message += `Resource returned ${error.name}`; } else if (error instanceof Error) { - HalAwareErrorHandler.reportError(error); + window.ErrorReporter.captureException(error); } else if (error instanceof HttpErrorResponse) { - HalAwareErrorHandler.captureHttpError(error); + HalAwareErrorHandler.captureError(error); message = error.message; } else if (typeof error === 'string') { window.ErrorReporter.captureMessage(error); @@ -55,18 +55,14 @@ export class HalAwareErrorHandler extends ErrorHandler { super.handleError(message); } - private static reportError(error:Error):void { - window.ErrorReporter.captureException(error); - } - /** - * Report any 5xx errors to sentry, if configured. - * @param httpError + * Report any errors to sentry, if configured. + * Sentry will filter according to their error status + * + * @param error * @private */ - private static captureHttpError(httpError:HttpErrorResponse):void { - if (httpError.status >= 500) { - HalAwareErrorHandler.reportError(httpError); - } + private static captureError(error:Error|HttpErrorResponse):void { + window.ErrorReporter.captureException(error); } }