Angular.js: Response status code -1 for a call with absolute url

Created on 26 Oct 2015  路  4Comments  路  Source: angular/angular.js

I found this closed issue and updated this plnkr with the lastest angularjs version.

The call with absolute url still return a HTTP status -1, so I thing this bug is not fixed yet ?

I need to be able to handle 503 errors in my app, how can I do ?

Thanks

Most helpful comment

I think you are confusing a 503 response status with an unresponsive server. Status codes are not generated in the client (browser) but are sent by the server. If a server is not responding, the request will time out and the status code will be -1. A actual 503 response status has to be sent by the server, denoting that while the web-server itself is available and responding, the request cannot be properly handled, because the service is unavailable (e.g. the app is down for maintenance).

So, -1 denotes an aborted/timed out request (either the server is down or the client is not connected to the internet or the request was manually cancelled by the client).

All 4 comments

This isn't Angular-specific. It's a failure due to CORS. If you use an absolute URL on the same domain (or if you configured CORS correctly on the server-side), it works as expected.

Closing as it works as expected.

Hi @gkalpak thks for your answer, but here is my problem : at deploy time, the server doesn't respond during about 1 minute, so a 503 error occurs on the front-side because the server is unreachabled and cannot respond with CORS headers... and so on the front-side, angular gives me an error with status -1, so don't you think this is a bug ? I should be able to identify errors even if server-side is unreachable right ?

I think you are confusing a 503 response status with an unresponsive server. Status codes are not generated in the client (browser) but are sent by the server. If a server is not responding, the request will time out and the status code will be -1. A actual 503 response status has to be sent by the server, denoting that while the web-server itself is available and responding, the request cannot be properly handled, because the service is unavailable (e.g. the app is down for maintenance).

So, -1 denotes an aborted/timed out request (either the server is down or the client is not connected to the internet or the request was manually cancelled by the client).

Based on file https://github.com/angular/angular.js/blob/6706353a71e3c11c56c0b19be03600dac57aafe1/src/ng/http.js#L927

Status -1 usually means

  • the request was aborted, e.g. using a config.timeout.
Was this page helpful?
0 / 5 - 0 ratings