You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
onError does not handle error responses with 4xx or 5xx HTTP status codes, since these are considered "successful" responses but with a bad status code. In these cases you need to check the response's status property or ok() method via the onResponse callback.
The issue with using react-query alongside openapi-ts + openapi-fetch that I see is that it seems impossible expect if I miss something to grab the response code.
The usage pattern would be:
const{ mutateAsync,isPending: isInviting}=useMutation("post","/api/async-operation");consthandler=async()=>{try{constres=awaitmutateAsync(...);}catch(error){// Here error code should be able to be read if it was Fetch errorconsole.log(error)// Error just ends up being the body of the response and nothing else}}
I believe from other issues #2257#2231 and maybe more.
Reproduction
Expected result
Have the fetch's error response propagated if there is an error thrown.
I believe you're supposed to throw an error from within the fetch client so it can bubble up and let react-query react to it and pass it along into onError. Here's how I have mine set up:
/// later on... in another fileconst{ mutateAsync, isPending, error }=$api.useMutation("post","/api/auth/login",{onSuccess: (data)=>{navigate(ROUTES.DASHBOARD);},onError: (error)=>{setFormError("Invalid email or password");},});
openapi-fetch version
openapi-fetch
Description
Currently in the docs it says:
The issue with using react-query alongside openapi-ts + openapi-fetch that I see is that it seems impossible expect if I miss something to grab the response code.
The usage pattern would be:
I believe from other issues #2257 #2231 and maybe more.
Reproduction
Expected result
Have the fetch's error response propagated if there is an error thrown.
Extra
The text was updated successfully, but these errors were encountered: