Posts

Showing posts from July, 2018

Exception Handling with Angular (6.0.7)

Our target : globally catch errors. The angular way to catch error globally is to implement a custom  ErrorHandler . Basically, I would like to act differently when we have server or client errors. When the server notifies an error, Angular throws an  HttpErrorResponse . For client-side error we will have an Error instance instead. When the user is not authorized (401), he may be redirected to the login page. When the user is not allowed to see a resource (403), he may be redirected to the forbidden page. 1. The errors service Basically, this service takes all errors information and send them to an endpoint (e.g. Help Desk). 2. The errors handler The router navigation should only be triggered inside Angular zone. 3. The core routing module Please take a look at my demo . Don't hesitate to share and comment...