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

Inconsistent promise chaining with HttpPromise #11972

Closed
ajcrites opened this issue May 29, 2015 · 1 comment
Closed

Inconsistent promise chaining with HttpPromise #11972

ajcrites opened this issue May 29, 2015 · 1 comment

Comments

@ajcrites
Copy link

The $http special promise methods success and error do not always chain as expected. These should work with the promise chain as expected and also be fully interoperable with the $q methods .then and .catch.

http://plnkr.co/edit/csyUaNojCaUvN6k47V6C?p=preview

    $http.get("https://cors-test.appspot.com/test").success(function (data) {
      return $q(function (_, reject) { reject() });
    }).error(function () {
      console.log("first error should be logged, isn't");
    });

    $http.get("https://cors-test.appspot.com/test").success(function (data) {
      return $http.get("http://doesnt.exist/")
    }).success(function () {
      console.log("second error is incorrectly considered a success");
    }).catch(function () {
      console.log("second error should be logged, isn't");
    });

    $http.get("https://cors-test.appspot.com/test").then(function (data) {
      return $q(function (_, reject) { reject() });
    }).catch(function () {
      console.log("third error should be logged, is");
    });

    $http.get("https://cors-test.appspot.com/test").then(function (data) {
      return $http.get("http://doesnt.exist/")
    }).catch(function () {
      console.log("fourth error should be logged, is");
    });

This will emit

second error is incorrectly considered a success
third error should be logged, is
fourth error should be logged, is

The issue seems to be that if a promise is returned from the .success and .error callbacks, it is treated as a truthy value rather than continuing the promise chain. Instead, they should continue the promise chain.

ajcrites added a commit to ajcrites/angular.js that referenced this issue May 29, 2015
`.success` and `.error` methods will now continue the promise chain.
Returning a promise in either of these callbacks will be appropriately
handled by the chain.

Closes angular#11972
@gkalpak
Copy link
Member

gkalpak commented May 29, 2015

Based on the discussion at #4345 and #10508 (especially #10508 (comment)), it seems like success() and error() are heading for deprecation.

Note that fixing their "brokenness" would be quite of a breaking change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants