Skip to content
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

Closed

Description

@langdonx

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

Activity

  1. caitp commented on Jan 31, 2014

    @caitp
    Contributor

    I can't reproduce this on Chrome32 or FF29

  2. benjamingr commented on Jan 31, 2014

    @benjamingr
    Contributor

    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 Err null 0

    http://jsfiddle.net/5BVhD/

  3. langdonx commented on Jan 31, 2014

    @langdonx
    Author

    @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:

    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.

  4. chriswep commented on Feb 3, 2014

    @chriswep

    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.

  5. swallez commented on Feb 6, 2014

    @swallez

    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.

  6. langdonx commented on Feb 13, 2014

    @langdonx
    Author

    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.

  7. Francisc commented on Feb 27, 2014

    @Francisc

    What's the status with this issue?

  8. marcalj commented on Mar 1, 2014

    @marcalj

    Duplicated issue, sorry :p #6503

  9. added a commit that references this issue on Mar 1, 2014
    cfbb963
  10. added a commit that references this issue on Mar 14, 2014
    f108a2a
  11. allaLad commented on Jun 10, 2014

    @allaLad

    This fix is part of AngularJS v1.3.0-beta.11.
    Is it possible to get v1.2 be patched with the fix?
    Thanks

  12. langdonx commented on Jun 10, 2014

    @langdonx
    Author

    @allaLad I'm seeing the fix in 1.2.17, are you not?

  13. allaLad commented on Jun 10, 2014

    @allaLad

    I haven't seen it, it was released 2 days ago, we're using v1.2.9. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions