why useMutation onError never gets fired even when the server is down or API responds with 500? #3931
Unanswered
ritikbanger
asked this question in
Q&A
Replies: 2 comments 13 replies
-
you are not showing your api function :/ very likely, it doesn't return a rejected promise in case of an "error code 500". For example, the browser native |
Beta Was this translation helpful? Give feedback.
10 replies
-
yeah same problem.
if i submit with empty customer details, i get internal server error but onSuccess gets triggered and page is navigated to homepage, onError never gets triggerred... |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version: "react-query": "^3.39.1",
I am using useMutation hook and calling the mutateAsync function. The onSuccess of mutationAync fires always even when the API does not respond or responds with error code 500 or it fails.
Why onError is not triggered in such cases, is there a need to pass something explicitly somewhere or am I missing something here.
By defination of onError: This function will fire if the mutation encounters an error and will be passed the error.
If a promise is returned, it will be awaited and resolved before proceeding.
Since, if the api fails, the mutation will not receive any results or there will be no response but still onError is not trigerred.
Code:
Beta Was this translation helpful? Give feedback.
All reactions