3

In our project we already use a custom error handler using

{provide: ErrorHandler, useExisting: CustomErrorHandler}

This CustomErrorHandler is provided by third party which logs errors to a central server. In addition to this we want to implement our own central error handling to display errors on screen.

Is there a way to have multiple error handlers in angular?

1
  • 2
    Decorate CustomErrorHandler with your logic by overriding CustomErrorHandler Commented Apr 12, 2017 at 8:57

1 Answer 1

9

Thank you @yurzui, for anyone loooking for code here are the snippets that I used:

AppModule.ts:

{provider: ErrorHandler, useClass: LocalErrorHandler}

LocalErrorHandler.ts:

@Injectable()
export class LocalErrorHandler extends CustomErrorHandler
{
   handleError(error: any)
   {
       //Local custom handling
       super.handleError(error);
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

But it does not look easy to plug and play like interceptor. Do you have other implement ? @yurzui
@HungCung what do you mean by not easy to plug and play like interceptor? You just create a class and instead of useExisting, you will write useClass... this IS an interceptor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.