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

fix($http): continue promise chain with HttpPromise #11973

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
9 changes: 9 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down