1

I read this guide here: https://angular.io/guide/http#getting-error-details

And in the snippet the guide provides the code tries to differentiate: a) client side error (like no connection etc) and b) backend responses (see code in the guide or in the pic below).

I did implement this code for my case and surprisingly when I do offline mode in Chrome dev tools (set offline flag) - I catch those errors as "backend" errors while I thought it should be the client error.

See below what error I get and my code snippet (same as in the guide):

enter image description here

This is a snapshot of the console.log - where clearly this message "Backend returned..." should have been shown if there was in fact server side response.

What am i missing here? Is this code: err.error instanceof Error - even valid?

enter image description here

1 Answer 1

2

The example seems to be a little outdated. HttpClient uses XHR backend under the hood and what the documentation refers to as client side error is XHR errors delivered through the error callback:

var oReq = new XMLHttpRequest();
oReq.error = handler()

According to the spec, XHR errors are instances of ProgressEvent interface, so the this check should be added:

if (e.error instanceof Error || e.error instanceof ProgressEvent) { }
Sign up to request clarification or add additional context in comments.

5 Comments

Hey thank you for your response, I did see the ProgressEvent was logged during those errors and was wondering!:) So am I right to say that current guide at angular.io is not up to date then?
@SergeyRudenko, yeah, I created a pull request.
As of today, e.error instanceof ProgressEvent returns false. I wonder why. Based on the debug watch, it is a ProgressEvent but the statement e.error instanceof ProgressEvent returns false!
@hjchin, interesting, thanks. Can you maybe create a stackblitz demo? I just checked the spec and it hasn't changed so an error should be an instance of ProgressEvent
I have the same issue, console.log of e.error is showing a ProgressEvent but instanceof is returning false. see github.com/IsraelHikingMap/Site/issues/1660 @MaxKoretskyi did you find a solution for this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.