-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http): pass success flag to transformResponse #6734
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Hi @just-boris , thnx for this pull request. I'm kind of the fence when looking on this one, since I'm not sure how common this use-case is and it could be already covered with interceptors, if I'm not mistaken. The transform function should be probably getting the whole request / response object in the first place, but then it is even closer to interceptors. So yes, maybe we should just stick to interceptors... Would it work for your use-case? If others weight to merge it, it would require doc update here: Line 545 in 8d0cb30
|
@pkozlowski-opensource you can define a different |
This feature would be really useful. transformResponse is all about mutating the response received from the server. Now I don't think it is a rare case to mutate it depending on the success or failure of the request. I mean we already get access to all the headers in the second param, it is a little strange that we can't access the status of the response itself. |
I would find this feature very useful. This PR does seem to address an intended use case. According to the documentation, However using an interceptor for authentication and |
02dc2aa
to
fd2d6c0
Compare
+1 |
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
This is old, but... +1, I had expected that |
+1 |
We should land this one, it solves #10324 as well |
@just-boris I know we were slow on this one, I'm sorry for this. We want to land this one - would you mind rebasing it on top of the current master? |
I'm going to put into the 1.4 milestone as I think we should seriously consider not invoking response transform functions in case of error. Would be great to have more feedback on this from people but yeh, for now I'm leaning towards removing invocation of transform functions for failed responses. |
Agreed. An error response very rarely, and never in my use cases to date, is transformed in the same way a success response is. A separate transform function for errors might work. The key here being: 'transformed the same way' |
I actually disagree with this line of thinking --- If I request "/me" and get a 403, that 403 might have information in JSON that I care about. a website will render HTML on a 404, we should still transform error responses. The only case where it doesn't make a lot of sense is the NetworkError case, but we can't really do that because mobile apps sometimes send responses that look like NetworkErrors for valid responses. |
Yeh... Still, people often need to know (for whatever reason) if a given response was success / error. So we've got several options here:
What would you suggest @caitp |
I think we can return the status code to |
OK then, let's try this approach in 1.3.x and if anything else bad surfaces we can take more radical steps in 1.4 |
good! |
Request Type: feature
How to reproduce:
Component(s): $http
Impact: small
Complexity: small
This issue is related to:
Detailed Description:
Other Comments:
Now
transformResponse
doesn't know about request is successful or not.So, it is impossible to make some transformation only on success response. For example, I wrap response into object for easier handling:
When request has failed, response doesn't contain a fields required by the post and it causes an Exeption.
With this fix I will can create the post only from success responses