From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Writing a custom error handler class

Writing a custom error handler class - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Writing a custom error handler class

- [Instructor] In the last video we added a new file using Angular CLI tool. Let's update this file to add metadata to error messages before sending them to the console. I have our new file open here in VS code and the first thing we need to do is import Angular's ErrorHandler class. I do that by going to the import statement for the Angular core module at the top of the file and adding the ErrorHandler class to the list of imports. If you're using VS code or something similar you may get help with auto-completion. Please take advantage of that. I know I will. I'm going to hit tab to use the suggestion provided by the editor. Next we can get rid of the constructor. We won't need that for our service. Then we want to implement the ErrorHandler class. We do that by going just before the opening bracket of our class and typing implements ErrorHandler. You may see a wavy red line under the class name if you're using VS code, this is the editor telling us there's an error. If we hover over…

Contents