How to handle error in react-query's onSuccess event?
I want to fire a function in onSuccess event but this function can failed. What is the best to handle this?
8 Replies
quickest-silver•3y ago
What should happen if it fails?
flat-fuchsiaOP•3y ago
retry the function and if it fails again modify the database
quickest-silver•3y ago
Why not use the retry option?
flat-fuchsiaOP•3y ago
because if mutation finished ok i dont want to create a new record again
i want to excute the function after de mutation again
quickest-silver•3y ago
first time you're mentioning it's about mutations ....
because if mutation finished ok i dont want to create a new record againi still don't understand this, sorry. can you try being a bit more descriptive? the retry function (on mutations and queries) is called when the actual mutationFn (or queryFn) fails. So if it succeeds, it will not be called. But it will be called if it fails I think I misread the question but it's hard to decipher 😅
flat-fuchsiaOP•3y ago
Sody if my english is not the best
I am excuting a function inside on sucess:
The functionB can fail and i want to retry it 2 times
I it continues failing i need to update the database again
quickest-silver•3y ago
is functionB also a mutation?
flat-fuchsiaOP•3y ago
no
but if retries 3 times and it doesnt finish correctly i want to save a variable in the database (a mutation)
@TkDodo 🔮 Sory i bother you but i couldnt found a good approach