transformResponse runs, even if error code is received
See original GitHub issueSteps To Reproduce
- Make an axios request to an endpoint that will return an error code (i.e.
404
or500
.
Expected Result
transformResponse
should not run
Actual Result
transformResponse
runs, attempting to transform a response that is, i.e.
- empty
- an HTML description of the 404
- etc
the actual error code is not allowed to bubble up to the catch
listener
instead we generally get some sort of syntax error (without copious defensive programming techniques)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:6
Top Results From Across the Web
Handling 401 in axios when using both interceptors and ...
The thing is, when server sends 401 response on my GET request, transformResponse code runs and tries to modify server response, ...
Read more >How to execute the code in transformResponse at serverless ...
It works well in local, but it doesn't work when deployed. If I enter the “/example-react-progressive-web-apps-ecommerce” URL after the ...
Read more >HTTP status and error codes for JSON | Cloud Storage
This code applies even if the resource being acted on doesn't exist. insufficientPermissions, According to access control policy, the current user does not...
Read more >How to Perform HTTP Requests with Axios – A Complete Guide
When we send an HTTP request to a remote server, we get a response with specific ... status - the HTTP code returned...
Read more >Redux Essentials, Part 8: RTK Query Advanced Patterns
You should see a GET request to /posts as we fetch the initial data. ... We've still got a couple bits of code...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
transformResponse
is a lovely design pattern for transforming the response in the way the client requires it if the service doesn’t quite do that, or if a specific client needs to do something different with response data compared to another client. Or if we just want the response as a JavaScript object rather than a string. It’s a more pleasant pattern than using interceptors or dealing with each response in a different way.To keep our code clean and to negate unnecessary and harder-to-maintain defensive programming, it would be great if we can define different transforms for success responses compared to error responses. Perhaps
transformResponse
could continue to handle both (to ensure no breaking changes) buttransformSuccessResponse
andtransformErrorResponse
could be added to help us with this?In my case I need to use transformResponse to convert a string representation of json to actual json. The api call is to a third party so I can’t correct the response coming from the API