Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($http): reject $http promise when timeout occurs #7688

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Jun 4, 2014

Previously, timed out $http requests would result in a fulfilled promise, rather than a rejection. This CL corrects this unexpected behaviour.

BREAKING CHANGE:

Currently, request timeout is treated as a successful request. This is unexpected, as a timeout is generally a failure, however it's possible some applications depend on this behaviour.

If your application depends on this, it's possible to migrate by simply moving the code which handles a timeout into a rejection/error handler, rather than a success handler.

Example:

$http.get('/some/slow/resource', {
  timeout: 1
}).
  error(function(res) {
    if (res.statusText === "Timedout") {
      console.log("request timed out!");
    }
  });

Fixes #7686

@caitp caitp added this to the 1.3.0-beta.11 milestone Jun 4, 2014
Previously, timed out $http requests would result in a fulfilled promise, rather than a rejection.
This CL corrects this unexpected behaviour.

BREAKING CHANGE:

Currently, request timeout is treated as a successful request. This is unexpected, as a timeout is
generally a failure, however it's possible some applications depend on this behaviour.

If your application depends on this, it's possible to migrate by simply moving the code which handles
a timeout into a rejection/error handler, rather than a success handler.

Example:

    $http.get('/some/slow/resource', {
      timeout: 1
    }).error(function(res) {
      if (res.statusText === "Timedout") {
        console.log("request timed out!");
      }
    });
@campersau
Copy link
Contributor

I think it should be res.statusText === "Timeout" in your example.

@caitp
Copy link
Contributor Author

caitp commented Jun 4, 2014

We're basically inventing a statusText for this, which might not happen in the version of this that ships. I'll see what Igor thinks about it later today

@caitp caitp closed this in ff791c9 Jun 6, 2014
caitp added a commit that referenced this pull request Jun 6, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$http turns timeout into success using 'then' instead of failure via 'reject'
2 participants