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
Currently using useMutation is not possible to throw error to error boundary only if it is not handled in other way.
For example:
const[mutate]=useMutation(()=>Promise.reject({status: 422}),{useErrorBoundary: true,throwOnError: true})try{awaitmutate(payload);}catch(error){if(error.status===422){return{message: "this is known exception"};}throwerror;}
or:
returnmutate(payload,{onError(error){if(error.status===422){return{message: "this is known exception"};}throwerror;}})
I am not sure what state should be in this case, but I should be able to convert the exception from the server before throwing it to the boundary.
The text was updated successfully, but these errors were encountered:
czterystaczwarty
changed the title
[feature] useMutation: add ability to handle errors in onError hook or rethrow it to boundaries
[feature] useMutation: add ability to handle server error before rethrow it to boundary
Jun 2, 2020
You can do this in 2.0 (and quite possibly in 1.x as well) by simply mutating the error object. In 2.0, you are also given better callback order, which should let you more easily make these changes at the right timing (mutate side-effects run after useMutation ones)
I'm not sure this is right order.
In my opinion onError hooks should be called from more specific to more general (eventually to boundary if not handled earlier).
Currently using
useMutation
is not possible to throw error to error boundary only if it is not handled in other way.For example:
or:
I am not sure what
state
should be in this case, but I should be able to convert the exception from the server before throwing it to the boundary.The text was updated successfully, but these errors were encountered: