-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Resource interceptor is not actually an interceptor, just a function that returns what becomes result of resource promise. #11409
Comments
That does seem very confusing. I think we either need to make some changes to |
Adding a little context: It doesn't really have to do with the interceptors, but with the internal workings of For "its own reasons", This has been discussed in more detail in #11201 (expecially #11201 (comment) and #11201 (comment)). |
@gkalpak thanks for linking to the previous discussion on this. The fact that this has come up again and, IMO is not very intuitive, I wonder if we ought to make a change to
2 seems to be fairly arbitrary and in either case would break some uses irreparably. 1 seems to be a breaking change that doesn't really add any value except remove unexpected behaviour; but I would definitely consider it... |
@petebacondarwin, I too agree that we could do better inside Your 1st suggestion will be a breaking change indeed, but I wouldn't say it will remove unexpected behaviour. I see it more like making the bahaviour consistently unexpected (with both default and custom interceptor) 😃 2a/2b would probably be better than what is happening today, but still unexpected imo and also breaking changes, so less than ideal 😞 Looking further into it, it seems that So, here are the several phases (in an (over)simplified version) between a call of a
I don't know how we can make things right, without a breaking change :( Ideally, I would expect that Even if we choose to always execute the default interceptor and keep everything else unchanged, it is still kind of unexpected that a user-defined interceptor will be passed a Any ideas ? |
One idea: Since it is unlikely that the user wants to bypass the default *: WARNING - I am not good with names :) Pros:
Cons:
|
For me it's not the problem that 'interceptor' in $resource replaces the default one, or even not so much that it behaves differently. For me the problem is that it's named exactly the same as interceptors that you can add to $http and especially that the documentation of $resource here https://docs.angularjs.org/api/ngResource/service/$resource doesn't describe its specific behaviour and even links directly to page that describes $http interceptors: https://docs.angularjs.org/api/ng/service/$http I updated the example here: http://jsfiddle.net/Lzgts/277/ to demonstrate how should you write $resource 'interceptor' to achieve same behaviour as from $http interceptor. |
I know I'm bumping an old discussion but has anything ever come of this? I'm finding myself in need of modifying the response to a $resource request but unable to do so because nothing fires before it turns everything into Resource objects. One would generally expect interceptors to fire before that (i.e. moving the .then() that fires the interceptor to be first in line) and transforms could then be fired afterwards. |
@BenWoodford There is work going on to fix this in #13273 - please take a look at the implementation there and comment. It is scheduled to be incorporated after we get to 1.6.0 |
Here you can see that behaviour of interceptor added to $httpProvider.interceptors is completely different from interceptor declared in resource methods: http://jsfiddle.net/Lzgts/269/
I think we need to update the documentation to reflect this changing the behaviour now might break apps of people who adapted to this behaviour.
That's how I found out about this bug. Behaviour of my app was different when I stopped needing the resource interceptor. After removing it app stopped working properly, but leaving it doing nothing as shown at https://docs.angularjs.org/api/ng/service/$http in section on Interceptors kept the app working properly.
The text was updated successfully, but these errors were encountered: