-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response is undefined in the event of an error #384
Comments
In the case of an error, the error property of the hook return value is populated with the error full response, see: Line 154 in 3bcd010
Does this do what you need? |
Hmm, yes, this appears to do exactly what I need. That's so obvious that I had already tried it when I submitted this issue and "error" was simply a printed error summary, not a response object. So yep, this is an upstream (or cross-stream) issue. The error thrown by So it's a case of the mock adapter being far lower level than I expected. Apologies for the poke, @simoneb, and thanks for the help🥇 |
No problem, glad you found a solution. |
Feature Request
In the event of an error, the
response
anddata
objects reurned by useAxios are undefined. I think this is intended behaviour, because the docs refer toresponse
explicitly as the "Success response object".I guess that makes this a feature request for the response object to contain the response irrespective of success state.
Without the full response in the event of an error, it's impossible to handle the error correctly (or differently according to what the error was).
Use Case
I built a
FormHandler
with axios-hooks that enables me to simply wrap any visual form component with a handler. However, unless there's something I can't see, it's not able to use axios-hooks because theresponse
value only updates on success, not on failure... so I'm not able to display field errors returned from the API in the form.Example
I submit some (invalid) data using POST request with useAxios:
From Chrome devtools, I can see a 400 response whose data looks like:
(I know. It's a test.)
useAxios Setup
In the following setup of useAxios,
const apiErrors = error ? response.data : {}
always produces undefined.The text was updated successfully, but these errors were encountered: