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?

Santhosh Kumar
  • 381
  • 1
  • 5
  • 13

2 Answers2

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)

Pengyy
  • 37,383
  • 15
  • 83
  • 73
  • 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 – Santhosh Kumar Apr 08 '17 at 00:01
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.

Santhosh Kumar
  • 381
  • 1
  • 5
  • 13