This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Inconsistent promise chaining with HttpPromise #11972
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels