Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource response transformation executed before HTTP interceptor #7594

ce07c3 opened this issue May 25, 2014 · 5 comments

Resource response transformation executed before HTTP interceptor #7594

ce07c3 opened this issue May 25, 2014 · 5 comments


Copy link

@ce07c3 ce07c3 commented May 25, 2014

Shouldn't it be the other way around? I would not want to transform a 401-response.

Copy link

@scriby scriby commented Jul 8, 2014

I ran into this today. When specifying an interceptor for a $resource action, the response interceptor runs after the response.resource object has been populated. I need to transform the data before the resources are constructed.

Copy link

@dtheodor dtheodor commented Sep 3, 2014

If I understand your use-case correctly, if you want to modify the data before they are turned into the Resource object you should use the transformResponse option. The interceptor is provided to modify the Resource object as it would be returned if there was no interceptor.

Copy link

@jonlil jonlil commented Nov 24, 2014

I also ran into this today, running angular & angular-resource 1.3.3. Added a method to $http.defaults.transformResponses chain that catches /Unauthorized/.test(arguments[0])

Any progress / updates?

Copy link

@pkozlowski-opensource pkozlowski-opensource commented Dec 14, 2014

A fix landed in master (1b74097) that makes it possible to inspect response status code in the response data transformer function and take an appropriate action based on this status. Hopefully this is enough to address this issue as now people can avoid response data transformation for failed requests.

Closing this for now, please open a separate issue if anything is missing after this change.

Copy link

@dchacke dchacke commented Jan 26, 2016

To anyone coming here from Google like I did:

I also found it to be confusing that response interceptors run after the transformResponse method. I followed @jonlil's advice and also added a method to $http.defaults.transformResponse. Here is an example from the documentation on how to do that.

So, if you need to basically have a response interceptor that runs before the transformResponse method, this should do it:

'use strict';

  .run(function ($http) {
    $http.defaults.transformResponse.push(function (data, headers) {
      // do stuff here before the response transformation

      // Be sure to return `data` so that the next function in the queue can use it.
      // Your services won't load otherwise!
      return data;

If your services or http calls don't have their own response transformer, you're good now.

If your services do have their own transformResponse method, they will actually override all default transformers (I found this out after a long read of the documentation), and the above code will not run.

To circumvent this, you can follow this example in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants