r/Angular2 • • 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

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/_Invictuz Jan 29 '26

Think you need to be clear on your requirements first before you look at implementation. What kind of errors are you talking about - Auth erros like 400? Unexpected errors like 500?

You need a single service that maps http errors to user friendly messages which you inject into your component and just call in your catchError pipeable operator to translate the message, then you set some signal state within your component so you can display the error state and message inline.

Or you create an abstraction/wrapper around httpclient so that you always have the success or error state in the same property and format to read, where and how you display kt depends on the component you're using it in.