From 05e5ee1935e8723afd0bcf698cc7ba74ce24ce3c Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Thu, 28 May 2015 22:44:09 -0400 Subject: [PATCH] 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 #11972 --- src/ng/http.js | 4 ++-- test/ng/httpSpec.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index fdab62a776eb..973d74e59751 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -911,7 +911,7 @@ function $HttpProvider() { assertArgFn(fn, 'fn'); promise.then(function(response) { - fn(response.data, response.status, response.headers, config); + return fn(response.data, response.status, response.headers, config); }); return promise; }; @@ -920,7 +920,7 @@ function $HttpProvider() { assertArgFn(fn, 'fn'); promise.then(null, function(response) { - fn(response.data, response.status, response.headers, config); + return fn(response.data, response.status, response.headers, config); }); return promise; }; diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index ab4a9f43e878..6b0d30aa9457 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -458,6 +458,15 @@ describe('$http', function() { expect(httpPromise.success(callback)).toBe(httpPromise); }); + it('should continue promise chain with promise returned in HttpPromise callback', function() { + $httpBackend.expect('GET', '/url/a').respond(200); + $http({url: '/url/a', method: 'GET'}).success(function() { + $httpBackend.expect('GET', '/url/b').respond(400); + return $http({url: '/url/b', method: 'GET'}); + }).error(function(data, status) { + expect(status).toEqual(400); + }); + }); it('should error if the callback is not a function', function() { expect(function() {