You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$http incorrectly reports back 404 on canceled request #6074
As of 1.2.8, canceled $http requests return a status of 404, instead of 0. It's a little tricky to reproduce on a public fiddle, but here's how:
Load the following full-screen fiddle and just keep trying to refresh the page before the page has fully loaded (F5, F5, F5, F5...). Eventually you'll see an alert that says "error callback 404":
Chrome and Firefox give 404, so it's not browser specific. Firefox swallows the alert when you refresh, so you have to be quick to see it. I couldn't ever see the alert in IE, so.
I'm relying on this status code to handle and react to errors. My web server is a little slow, so I don't want to show a bunch of errors to the user when they refresh while they're waiting for it to come back.
i can confirm this problem. a request that fails via config.timeout works as expected with a status code of 0. if there is a browser(?) timeout (Chrome Canary here on OSX Mavericks, no answer from server after 90 seconds) the status code is 404 which is wrong.
Could this be related to 28fc80b where a status code 0 is changed to a 404 because of a bug in Android?
Practically this means we can't distinguish server down from a real 404.
It's interesting to note that there are positive benefits of this false 404.
When CORS requests fail in 1.2.7, they fail silently and the $http.error callback will be called, so my app is stuck in a wait state.
In 1.2.10 specifically (but probably in 1.2.8+), the $http.error receives an incorrect 404, and my app responds to it and sends the user to the error page.
It would be ideal to be able to detect the request failure if it failed because of CORS, but I'm not sure if it's possible.
Activity
caitp commentedon Jan 31, 2014
I can't reproduce this on Chrome32 or FF29
benjamingr commentedon Jan 31, 2014
I've written a more isolated test case, I can not seem to reproduce, getting 0 on Chrome 32
Logs
Err null 0http://jsfiddle.net/5BVhD/
langdonx commentedon Jan 31, 2014
@benjamingr Timeout doesn't have the status code issue. It's the cancelling of the XHR through refreshing the browser that causes the problem.
@caitp I've reproduced it on my site with a slow-running node.js service. Load the page and click refresh within 2 seconds.
http://home.langdonx.com/angular-http-test/test-1.2.1.html (gives status code 0)
http://home.langdonx.com/angular-http-test/test-1.2.7.html (gives status code 0)
http://home.langdonx.com/angular-http-test/test-1.2.8.html (incorrectly gives status code 404)
http://home.langdonx.com/angular-http-test/test-1.2.10.html (incorrectly gives status code 404)
The node service is as follows:
(Please be kind to my server ;))
It's easily reproducible on Chrome 32, Chrome 34, and Firefox 26. IE seems to just shut everything down on refresh.
chriswep commentedon Feb 3, 2014
i can confirm this problem. a request that fails via config.timeout works as expected with a status code of 0. if there is a browser(?) timeout (Chrome Canary here on OSX Mavericks, no answer from server after 90 seconds) the status code is 404 which is wrong.
swallez commentedon Feb 6, 2014
Could this be related to 28fc80b where a status code 0 is changed to a 404 because of a bug in Android?
Practically this means we can't distinguish server down from a real 404.
langdonx commentedon Feb 13, 2014
It's interesting to note that there are positive benefits of this false 404.
When CORS requests fail in 1.2.7, they fail silently and the $http.error callback will be called, so my app is stuck in a wait state.
In 1.2.10 specifically (but probably in 1.2.8+), the $http.error receives an incorrect 404, and my app responds to it and sends the user to the error page.
It would be ideal to be able to detect the request failure if it failed because of CORS, but I'm not sure if it's possible.
Francisc commentedon Feb 27, 2014
What's the status with this issue?
marcalj commentedon Mar 1, 2014
Duplicated issue, sorry :p #6503
fix($http): don't covert 0 status codes to 404 for non-file protocols
fix($http): don't covert 0 status codes to 404 for non-file protocols
allaLad commentedon Jun 10, 2014
This fix is part of AngularJS v1.3.0-beta.11.
Is it possible to get v1.2 be patched with the fix?
Thanks
langdonx commentedon Jun 10, 2014
@allaLad I'm seeing the fix in 1.2.17, are you not?
allaLad commentedon Jun 10, 2014
I haven't seen it, it was released 2 days ago, we're using v1.2.9. Thanks!