Creating a Global Error Handler

Learn how to create a global error handler for handling server and client-side errors.

The Angular framework provides the ErrorHandler class for handling errors globally in an Angular application. The default implementation of the ErrorHandler class prints error messages in the browser console window. To create a custom error handler for our application, we need to sub-class the ErrorHandler class and provide our tailored implementation for error logging:

  1. Create a file named app-error-handler.ts in the src\app folder of an Angular application.

  2. Add the following import statements:

Get hands-on with 1400+ tech skills courses.