How can i access server error response
Server returns
When I print out the error in the onError call back of useMutation, or access the error from the mutation itself like myMutation.error.msg
I get something like ": Request failed with status code 400"
How do i get access to this info returned from the server { error: "Invalid email or password." }
3 Replies
quickest-silver•3y ago
entirely depends on your data fetching lib. with fetch, its probably json parse the body?
passive-yellowOP•3y ago
I'm using axios
Where is the body coming from.
AuthService.post({ data: credentials }).request(), <--- this is the axios request
in onSuccss I would have access to the json returned by the server
but my problem is where to access the json returned in the onError
in the component
I was hoping to get the sever response in auth.error.message.
passive-yellowOP•3y ago
I found a good lead here
https://github.com/TanStack/query/discussions/1463
Looks to be what I want to do.
GitHub
Get error response object · TanStack query · Discussion #1463
Hi. A mutation I'm calling fails with 400, and in devtools I see the response: {"error":{"code":"INVALID_INPUT","message":"An application must have ...