views:

66

answers:

3

It appears that when you make an XhrHttpRequest from a script in a browser, if the browser is set to work offline or if the network cable is pulled out, the request completes with an error and with status = 0. 0 is not listed among permissible HTTP status codes.

What does a status code of 0 mean? Does it mean the same thing across all browsers, and for all HTTP client utilities? Is it part of the HTTP spec or is it part of some other protocol spec? It seems to mean that the HTTP request could not be made at all, perhaps because the server address could not be resolved.

What error message is appropriate to show the user? "Either you are not connected to the internet, or the website is encountering problems, or there might be a typing error in the address"?

I should add to this that I see the behavior in FireFox when set to "Work Offline", but not in Microsoft Internet Explorer when set to "Work Offline". In IE, the user gets a dialog giving the option to go online. FireFox does not notify the user before returning the error.

I am asking this in response to a request to "show a better error message". What Internet Explorer does is good. It tells the user what is causing the problem and gives them the option to fix it. In order to give an equivalent UX with FireFox I need to infer the cause of the problem and inform the user. So what in total can I infer from Status 0? Does it have a universal meaning or does it tell me nothing?

+1  A: 

Please see this question, which covers the same topic: http://stackoverflow.com/questions/872206/http-status-code-0-what-does-this-mean-in-ms-xmlhttp

Scott Stafford
So you would think. But that question settled on an answer for one specific browser (IE) for one specific condition (TCP connection was accepted and was closed gracefully). Another answer also listed some wininet.dll-specific nonstandard status codes. So 0 may just be a default nothing-else-seems-to-apply response. What information if any can be inferred from 0?
Mark Lutton
+1  A: 

It doesn't seem to be defined, so far as I can see, broadly speaking:

  1. 1xx - Informational responses,
  2. 2xx - success
  3. 3xx - Redirection
  4. 4xx - Client error
  5. 5xx - Server error

Based on pure -possibly crazy- speculation, could a status code of 0 be a boolean response from your function call?

David Thomas
No, it is definitely a Number.
Mark Lutton
@Mark, I thought as much, but it seemed worth a mention.
David Thomas
A: 

Let's just say it means "The server is not responding or is not reachable. For help, contact your network administrator."

Mark Lutton