Handle HTTP Errors in Angular with HttpErrorResponse

Share this video with your friends

Send Tweet

When communicating with some backend API, data travels over the network using the HTTP protocol. As such, failures may occur, be it on our own device (i.e. the browser) or on the server-side which may not be available or unable to process our request. We need to handle such error responses and give the user a proper feedback.

Bartosz
Bartosz
~ 7 years ago

Under what circumstances client side error message is set? Both 4xx and 5xx errors are handled by backend error message.

Juri Strumpflohner
Juri Strumpflohner(instructor)
~ 7 years ago

These errors happen when the HTTP request doesn't even start. It's mainly to distinguish between errors coming from the server like 4xx and 5xx as you correctly said and those that might happen before or when invoking the http client.

Bartosz
Bartosz
~ 7 years ago

Great, thanks.

~ 4 years ago

It is interesting how you infer if error is local or coming from backend, by checking if errr is instance of Error. Is this so by design ?

Juri Strumpflohner
Juri Strumpflohner(instructor)
~ 4 years ago

yeah basically if you set a breakpoint in the catch block, you can see those errors happening client-side before going through the network, come up as "Error" instance :)