2

While checking out logs for a production app I noticed many failed HTTP requests with responses containing the status codes of 0 and -1. What is the difference between the status codes 1 and 0?

I know these are not 'real' status codes as per the http spec so I was trying to find the difference between these codes so I could at least notify the user that something is wrong with a message like 'Unable to connect to server' or something similar.

Angular.io seems to be devoid of documentation about these but I was able to find this on the legacy angular documentation:

Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout

Does the same also apply to the newer versions of Angular? I am using Angular 4.0.1.

Brad C
  • 2,868
  • 22
  • 33
  • The docs say it's the code returned by the server. – Günter Zöchbauer Apr 27 '17 at 20:19
  • @GünterZöchbauer Yeah that is what the docs say... which doesn't make much sense giving that 0 and -1 are not real Http Status codes. :( – Brad C Apr 27 '17 at 20:51
  • What server are you using. A server can still return non-standard codes. – Günter Zöchbauer Apr 28 '17 at 02:59
  • I am using the latest version of IIS (10). I googled and couldn't find anything about these codes coming from IIS. I am still inclined to believe it is coming from Angular. I guess I'll have to grab Angular's source off of github and manually grep the status codes so I can answer my own question. :) – Brad C May 01 '17 at 15:39

1 Answers1

2

I'm looking for the same answer, but what I know for sure, is that if your angular app could not get response from the server, it will set status code 0 or -1 (because a http-status code is received from a server).

I noticed that status -1 is used for timed out calls and if the real request has not been sent (e.g. the preflight options request failed - due to no internet or CORS issues).

I'm not sure when the status 0 returns, but I've encountered it already. I don't know if those two statuses have been mixed throughout the releases of Angular.

Thomas Stubbe
  • 1,945
  • 5
  • 26
  • 40
  • If you happen to be running into this still - and you are running through API Gateway in AWS - you might want to check this thread https://stackoverflow.com/questions/35190615/api-gateway-cors-no-access-control-allow-origin-header/48860809#48860809 – Gabriel Doty Aug 13 '18 at 02:52