Skip to content

Commit 8537708

Browse files
committed
fix($resource): provide HTTP status to the success
provide status code to the success callback fixes angular#8341
1 parent 7a36d49 commit 8537708

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/ngResource/resource.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ function shallowClearAndCopy(src, dst) {
202202
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
203203
* - non-GET instance actions: `instance.$action([parameters], [success], [error])`
204204
*
205-
* Success callback is called with (value, responseHeaders) arguments. Error callback is called
206-
* with (httpResponse) argument.
205+
* Success callback is called with (value, responseHeaders, status) arguments. Error callback is
206+
* called with (httpResponse) argument.
207207
*
208208
* Class actions return empty instance (with additional properties below).
209209
* Instance actions return promise of the action.
@@ -613,7 +613,7 @@ angular.module('ngResource', ['ng']).
613613
promise = promise.then(
614614
function (response) {
615615
var value = responseInterceptor(response);
616-
(success || noop)(value, response.headers);
616+
(success || noop)(value, response.headers, response.status);
617617
return value;
618618
},
619619
responseErrorInterceptor);

test/ngResource/resourceSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,21 @@ describe("resource", function() {
811811
});
812812

813813

814+
it ('should provide http status code for success callback', function() {
815+
$httpBackend.expect('GET', '/CreditCard/123').respond(202, {id: 123, number: '9876'});
816+
817+
var statusCode;
818+
var cc = CreditCard.get({id: 123}, function(data, headers, status) {
819+
statusCode = status;
820+
});
821+
822+
$httpBackend.flush();
823+
824+
expect(cc).toEqualData({id: 123, number: '9876'});
825+
expect(statusCode).toBe(202);
826+
});
827+
828+
814829
it('should allow parsing a value from headers', function() {
815830
// https://github.com/angular/angular.js/pull/2607#issuecomment-17759933
816831
$httpBackend.expect('POST', '/CreditCard').respond(201, '', {'Location': '/new-id'});

0 commit comments

Comments
 (0)