-
Notifications
You must be signed in to change notification settings - Fork 27.5k
$http incorrectly reports back 404 on canceled request #6074
Comments
I can't reproduce this on Chrome32 or FF29 |
I've written a more isolated test case, I can not seem to reproduce, getting 0 on Chrome 32 var $http = angular.injector(["ng"]).get("$http");
$http.get('/echo/json', {timeout: 1, tested: true}).success(function(el){
console.log(response);
}).error(function(err,status){
console.log("Err",err,status);
}); Logs |
@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) The node service is as follows: http.createServer(function (req, res) {
var u = url.parse(req.url, true);
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end('{"complete": true}');
}, parseInt(u.query.value));
}).listen(process.env.PORT); (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. |
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? |
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. |
What's the status with this issue? |
Duplicated issue, sorry :p #6503 |
PR angular#5547 introduced conversion of all 0 status codes to 404 for cases where no response was recieved (previously this was done for the file:// protocol only). But this mechanism is too eager and masks legitimate cases where status 0 should be returned. This commits reverts to the previous mechanism of handling 0 status code for the file:// protocol (converting 0 to 404) while retaining the returned status code 0 for all the protocols other than file:// Fixes angular#6074 Fixes angular#6155
PR #5547 introduced conversion of all 0 status codes to 404 for cases where no response was recieved (previously this was done for the file:// protocol only). But this mechanism is too eager and masks legitimate cases where status 0 should be returned. This commits reverts to the previous mechanism of handling 0 status code for the file:// protocol (converting 0 to 404) while retaining the returned status code 0 for all the protocols other than file:// Fixes #6074 Fixes #6155
This fix is part of AngularJS v1.3.0-beta.11. |
@allaLad I'm seeing the fix in 1.2.17, are you not? |
I haven't seen it, it was released 2 days ago, we're using v1.2.9. Thanks! |
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":
http://jsfiddle.net/C4jRt/8/embedded/result/
In 1.2.7 and before, you'll get "error callback 0" as expected:
http://jsfiddle.net/C4jRt/7/embedded/result/
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.
v1.2.8 (incorrect)
http://jsfiddle.net/C4jRt/8
v1.2.7 (correct)
http://jsfiddle.net/C4jRt/7
The text was updated successfully, but these errors were encountered: