DEV Community

Discussion on: Global error page in Angular

Collapse
 
anirbmuk profile image
Anirban Mukherjee

It is an interesting point. The only problem I see with this approach is the need to write an error handler inside every route resolver. That kind of makes the components lose their purpose. I believe all the user needs is to navigate back to the page where he/she came from, and for that we can make use of @angular/common's Location class.

Another approach is - (if we want to stay on the same page) - is to use { skipLocationChange: true } when we navigate to /error.

Collapse
 
kostyatretyak profile image
Костя Третяк

That kind of makes the components lose their purpose.

No, it's not. On the contrary, we can use the components to the fullest, because we can use the appropriate component for the error handler:

<ng-container *ngIf="!httpErrorResponse">
  Current component code here
</ng-container>

<cst-http-errors [httpErrorResponse]="httpErrorResponse"></cst-http-errors>
Enter fullscreen mode Exit fullscreen mode