Throughout the learning process of Angular2, I have noticed that exceptions are often caught right at the point of the call. For example:
getHeroes(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
}
While this approach may work well for tutorials, it does not seem sustainable to me. I would prefer to have a global handler that can display an overlay or popup message to the user, log the error to the console, and allow for customization when needed (such as handling specific errors in a more user-friendly manner). This way, I wouldn't have to override error handling everywhere like Angular2 suggests.
Is there a way to achieve this kind of global error handling in Angular2?
P.S. An analogy in C# could be something like using Application_Error
in a global.asax file along with
TaskScheduler.UnobservedTaskException
for error handling.