Closed binki closed 6 years ago
I believe error.response will have what you are looking for. I built the error handler the same as the axios core.
https://github.com/mzabriskie/axios/blob/master/README.md#handling-errors
Ah. I didn’t make that connection even though I looked at that exact line of code, I can get to the response in my handler after all. Thanks for the help!
It might not be a bad idea to change the error handler to:
this.setState({ isLoading: false, response: err.response, error: err })
But there are probably ramifications by not setting response to null if the user does not first check if error is set.
Yeah. IMO, it’d be much nicer if response
were passed. I basically have to do the following in places where my server returns error information which I want to use/display in the response:
response = response || (error || {}).response || null;
semver says you may change something like that if you bump major. Not sure if people will catch the change in behavior when updating to a new version though. Let me know what you want to do. I think maybe the test case I wrote in #19 could still be useful? ;-)
I guess I’ll reopen this and let you decide what you want to do whenever you find time. No rush ;-).
v2.0.0 addresses this change. Now when an error occurs response
will contain the err.response
object.
For many error conditions, such as server reporting failure in its response, you still get a response from the server with data. See how to get the response in this situation.
I think react-axios should also pass in
response
when there is an error condition. It doesn’t look like it does currently.