1

I have the following code in say abcd.js:

$http({url: 'some url' , method: 'POST', data: , headers: {}
}).then(function(response)) {
.............
}, function error(response) {
..............
})

In the case of error the values of response.status = -1, response.statusText ="". Basically no useful info. However in the Chrome Debugger console output I see:

POST: Some URL/analysis.php net::ERR_NETWORK_IO_SUSPENDED

The chrome debugger extracts the real error from the analysis.php network packet and displays it. Q1: Why is that the status and statusText dont have useful info?

Q2: Is it possible to get programmatically the network error? In the above failure example I would get it as ERR_NETWORK_IO_SUSPENDED.

Q3: Programmatically is there any other way to get the network error when $http() fails?

2
  • attention to http://stackoverflow.com/questions/37429136/angularjs-with-global-http-error-handling Commented Apr 8, 2017 at 0:24
  • Wow! Thanks that tells exactly how to wrap up my http call. This aligns with the Q3. Commented Apr 8, 2017 at 0:32

2 Answers 2

1

Q1: Why is that the status and statusText dont have useful info?

because you cannot reach the server, you won't get useful status code from the server.

Q2: Is it possible to get programmatically the network error?

you can set timeout to $http to catch network problems manually.

Q3: Programmatically is there any other way to get the network error when $http() fails?

take advantage of error callback of $http? (I don't know well about this)

Sign up to request clarification or add additional context in comments.

1 Comment

Q1: Thanks now I know I cannot expect anything from the returned error code. Q3: The error callback object is response and that has not useful info Q2: That is a good suggestion. Let me try putting the timeout, good idea thanks
0

After much Googling I found out that when ever I get the status = -1 that means the server was not reached at all because of some unknown reasons. All the unknown reasons are bundled under one error string ERR_NETWORK_IO_SUSPENDED. I do get a -1 and now I have simply hard coded the error string as ERR_NETWORK_IO_SUSPENDED. For other error code such as 400, 404 the status does get the number bad statuText has the correct string. So this confirmed $http() call is fine. With that said we can close this case. Thanks to all who helped to arrive at this conclusion.

Comments

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.