question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

transformResponse runs, even if error code is received

See original GitHub issue

Steps To Reproduce

  1. Make an axios request to an endpoint that will return an error code (i.e. 404 or 500.

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:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:6

github_iconTop GitHub Comments

10reactions
calumjamescommented, Dec 2, 2019

Can I ask why you guys use transformResponse ? I was thinking to put the data transformation logic in the transformResponse, but not sure if it is a right place to do so, espcially seeing this issue !

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) but transformSuccessResponse and transformErrorResponse could be added to help us with this?

1reaction
ventralnetcommented, Nov 30, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found