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

feature($resource): Add Resource To Response For Error Interceptors #16109

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: 5 additions & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ function shallowClearAndCopy(src, dst) {
* [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
* - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
* `response` and `responseError`. Both `response` and `responseError` interceptors get called
* with `http response` object. See {@link ng.$http $http interceptors}.
* with `http response` object. See {@link ng.$http $http interceptors}. In addition, The
* resource object is accessible by the `resource` property of the `http response` object.
* - **`hasBody`** - `{boolean}` - allows to specify if a request body should be included or not.
* If not specified only POST, PUT and PATCH requests will have a body.
*
Expand Down Expand Up @@ -776,6 +777,9 @@ angular.module('ngResource', ['ng']).
response.resource = value;

return response;
}, function(response) {
response.resource = value;
return $q.reject(response);
});

promise = promise['finally'](function() {
Expand Down
1 change: 1 addition & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ describe('basic usage', function() {
expect(callback).toHaveBeenCalledOnce();

var response = callback.calls.mostRecent().args[0];
expect(response.resource).toBe(ccs);
expect(response.status).toBe(404);
expect(response.config).toBeDefined();
});
Expand Down