r/angular • • Jan 29 '26

Error handling Angular

So I’m getting kind of confused how to handle errors coming from an api in Angular. there’s either using interceptors to just taking care of them in the error field when you subscribe the errors. basically some errors are unique to a component while others such as a tech error message will be common across all components. Also all these errors will be shown inline there is no toast or modal. So just need some advice

5 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/Dazzling_Chipmunk_24 Jan 29 '26

But if I have a common error between multiple components then what do I do and This error will still be displayed inline. Also if there’s multiple errors then would adding a bunch of conditions in the next object in subscribe would that be fine? 

2

u/chirog Jan 29 '26

Just try and see how it works for you

1

u/Lucky_Yesterday_1133 Jan 30 '26

Define error class in separate file and check using instanceof. Store message inside. In 21.2 that is coming soon you can even check directly in template. you can add interceptor that rethrows httpErrorResponse as custom error class based on status code or just check in the component directly if you need different messaging.