Skip to content

Commit 05e5ee1

Browse files
committed
fix($http): continue promise chain with HttpPromise
`.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
1 parent 291d7c4 commit 05e5ee1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ng/http.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ function $HttpProvider() {
911911
assertArgFn(fn, 'fn');
912912

913913
promise.then(function(response) {
914-
fn(response.data, response.status, response.headers, config);
914+
return fn(response.data, response.status, response.headers, config);
915915
});
916916
return promise;
917917
};
@@ -920,7 +920,7 @@ function $HttpProvider() {
920920
assertArgFn(fn, 'fn');
921921

922922
promise.then(null, function(response) {
923-
fn(response.data, response.status, response.headers, config);
923+
return fn(response.data, response.status, response.headers, config);
924924
});
925925
return promise;
926926
};

test/ng/httpSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ describe('$http', function() {
458458
expect(httpPromise.success(callback)).toBe(httpPromise);
459459
});
460460

461+
it('should continue promise chain with promise returned in HttpPromise callback', function() {
462+
$httpBackend.expect('GET', '/url/a').respond(200);
463+
$http({url: '/url/a', method: 'GET'}).success(function() {
464+
$httpBackend.expect('GET', '/url/b').respond(400);
465+
return $http({url: '/url/b', method: 'GET'});
466+
}).error(function(data, status) {
467+
expect(status).toEqual(400);
468+
});
469+
});
461470

462471
it('should error if the callback is not a function', function() {
463472
expect(function() {

0 commit comments

Comments
 (0)