sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

ref(angular): using InjectionToken and optional configuration

Open iaosee opened this issue 6 months ago • 3 comments

Using InjectionToken and optional configuration. This way I can inject the SentryErrorHandler into my custom ErrorHandler.

Before submitting a pull request, please take a look at our Contributing guidelines and verify:

  • [ ] If you've added code that should be tested, please add tests.
  • [x] Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

iaosee avatar Jul 01 '25 03:07 iaosee

In fact, using the spread operator in a literal object will not throw a TypeError .

{ ...null };
{ ...undefined };
var a = null;
var  b = undefined;
var  c = { n: 'cccc', ...a, ...b };

To be on the safe side, I changed it to

{
  logErrors: true,
  ...(options || {}),
}

iaosee avatar Jul 01 '25 10:07 iaosee

Hey @iaosee, thanks for opening up this PR and sorry for the long delay to getting back to you.

Could you explain your use-case a bit more in detail?

We typically recommend extending our error handler: https://docs.sentry.io/platforms/javascript/guides/angular/features/error-handler/#multiple-error-handlers

Does that not work for you?

andreiborza avatar Dec 04 '25 13:12 andreiborza

Hey @andreiborza, thanks for your reply.

It works perfectly, that's what I'm doing now. However, replacing "errorHandlerOptions" with "InjectionToken" here is a better practice. Now there are no problems; you can merge or close this PR.

iaosee avatar Dec 06 '25 06:12 iaosee

Thanks, I'll close this for now because it's a breaking change. We can think of revisiting/changing this if more people run into.

andreiborza avatar Dec 11 '25 09:12 andreiborza