diff --git a/packages/angular/src/errorhandler.ts b/packages/angular/src/errorhandler.ts index 31f945b08731..5e62a86dd0ff 100644 --- a/packages/angular/src/errorhandler.ts +++ b/packages/angular/src/errorhandler.ts @@ -1,12 +1,14 @@ import { HttpErrorResponse } from '@angular/common/http'; import type { ErrorHandler as AngularErrorHandler, OnDestroy } from '@angular/core'; -import { Inject, Injectable } from '@angular/core'; +import { Inject, Injectable, InjectionToken, Optional } from '@angular/core'; import type { ReportDialogOptions } from '@sentry/browser'; import * as Sentry from '@sentry/browser'; import type { Event } from '@sentry/core'; import { consoleSandbox, isString } from '@sentry/core'; import { runOutsideAngular } from './zone'; +export const SENTRY_ERROR_HANDLER_OPTIONS = new InjectionToken('errorHandlerOptions'); + /** * Options used to configure the behavior of the Angular ErrorHandler. */ @@ -86,10 +88,10 @@ class SentryErrorHandler implements AngularErrorHandler, OnDestroy { /** The cleanup function is executed when the injector is destroyed. */ private _removeAfterSendEventListener?: () => void; - public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) { + public constructor(@Inject(SENTRY_ERROR_HANDLER_OPTIONS) @Optional() options?: ErrorHandlerOptions) { this._options = { logErrors: true, - ...options, + ...(options || {}), }; } diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index f0911eb9a440..53520d28cb48 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -3,7 +3,7 @@ export type { ErrorHandlerOptions } from './errorhandler'; export * from '@sentry/browser'; export { init, getDefaultIntegrations } from './sdk'; -export { createErrorHandler, SentryErrorHandler } from './errorhandler'; +export { createErrorHandler, SentryErrorHandler, SENTRY_ERROR_HANDLER_OPTIONS } from './errorhandler'; export { browserTracingIntegration, TraceClass,