Skip to content

Commit 33c0ab1

Browse files
committed
ref(angular) ♻️ refactor SentryErrorHandler, using InjectionToken and optional configuration
1 parent bc6725c commit 33c0ab1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { HttpErrorResponse } from '@angular/common/http';
22
import type { ErrorHandler as AngularErrorHandler, OnDestroy } from '@angular/core';
3-
import { Inject, Injectable } from '@angular/core';
3+
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
44
import type { ReportDialogOptions } from '@sentry/browser';
55
import * as Sentry from '@sentry/browser';
66
import type { Event } from '@sentry/core';
77
import { consoleSandbox, isString } from '@sentry/core';
88
import { runOutsideAngular } from './zone';
99

10+
export const SENTRY_ERROR_HANDLER_OPTIONS = new InjectionToken<ErrorHandlerOptions>('errorHandlerOptions');
11+
1012
/**
1113
* Options used to configure the behavior of the Angular ErrorHandler.
1214
*/
@@ -86,7 +88,7 @@ class SentryErrorHandler implements AngularErrorHandler, OnDestroy {
8688
/** The cleanup function is executed when the injector is destroyed. */
8789
private _removeAfterSendEventListener?: () => void;
8890

89-
public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) {
91+
public constructor(@Inject(SENTRY_ERROR_HANDLER_OPTIONS) @Optional() options?: ErrorHandlerOptions) {
9092
this._options = {
9193
logErrors: true,
9294
...options,

packages/angular/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export type { ErrorHandlerOptions } from './errorhandler';
33
export * from '@sentry/browser';
44

55
export { init, getDefaultIntegrations } from './sdk';
6-
export { createErrorHandler, SentryErrorHandler } from './errorhandler';
6+
export { createErrorHandler, SentryErrorHandler, SENTRY_ERROR_HANDLER_OPTIONS } from './errorhandler';
77
export {
88
browserTracingIntegration,
99
TraceClass,

0 commit comments

Comments
 (0)