Earlier in this newsletter, we covered how to handle errors with RxJs Observables. What about errors in the rest of the application? Javascript has a primary try/catch mechanism, but this doesn’t help handle errors in a generic, unified way.
Fortunately enough, Angular has an ErrorHandler
interface that can be implemented by global error handler services such as this one:
That way, we can implement a catch-all method to deal with errors and display them to the user consistently (code example here). Even better, such a service could report errors to a server for further investigation and debugging from the dev team.
Here is a link to my custom error-handling tutorial to see a good example of how to implement a ErroHandler
service.