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

fix($resource): provide HTTP status to the success #8841

Closed
wants to merge 1 commit into from
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
6 changes: 3 additions & 3 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ function shallowClearAndCopy(src, dst) {
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
* - non-GET instance actions: `instance.$action([parameters], [success], [error])`
*
* Success callback is called with (value, responseHeaders) arguments. Error callback is called
* with (httpResponse) argument.
* Success callback is called with (value, responseHeaders, status) arguments. Error callback is
* called with (httpResponse) argument.
*
* Class actions return empty instance (with additional properties below).
* Instance actions return promise of the action.
Expand Down Expand Up @@ -613,7 +613,7 @@ angular.module('ngResource', ['ng']).
promise = promise.then(
function (response) {
var value = responseInterceptor(response);
(success || noop)(value, response.headers);
(success || noop)(value, response.headers, response.status);
return value;
},
responseErrorInterceptor);
Expand Down
15 changes: 15 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,21 @@ describe("resource", function() {
});


it ('should provide http status code for success callback', function() {
$httpBackend.expect('GET', '/CreditCard/123').respond(202, {id: 123, number: '9876'});

var statusCode;
var cc = CreditCard.get({id: 123}, function(data, headers, status) {
statusCode = status;
});

$httpBackend.flush();

expect(cc).toEqualData({id: 123, number: '9876'});
expect(statusCode).toBe(202);
});


it('should allow parsing a value from headers', function() {
// https://github.com/angular/angular.js/pull/2607#issuecomment-17759933
$httpBackend.expect('POST', '/CreditCard').respond(201, '', {'Location': '/new-id'});
Expand Down