handle onError mutation
want to show a toast when an error occured, so i copy and paste theo emoji project code but somehow still showing general error, any ideas thanks
11 Replies
anyone ?
Also I think its "cleaner" to do:
Just log the e to understand what is giving your error
hey did you figure this out?
If your callback it's working, that is, putting a console.log() outputs to console, i can't know the error with the given information. But i think the problem is that your callback is not being called at all. Maybe the error throw on api side it's correct, or maybe you query is always retrying, so the erro callback it's no called until the number os retries end.
yeah the callback is not triggering at all.
When exactly is the onError triggerred?
I've tried throwing errors on the api side but still no luck.
try defining it on the query level, and not when you mutate... try, but I think it's something like this
and yes, throwing errors or returning errors on the server-side should trigger this onError callback
Can you show how you're returning error on API side?
One unrelated problem is that the last
else
throw doesn't pass the info to the catch, since you don't use the error
of the try catch
block.
But anyway, throwing a TRPCERROR
it's enough to trigger the error on the client.
I've made a simple endpoint using the t3-app scafolder just to demonstrate:
The mutation on a client component:
The mutate call:
The console:But if you have retry enabled:
This happens:
This way, the error is never thrown.
If instead of
retry:true
you have retry:5
, with e.g retryDelay:2000
, it will take 10 seconds( 5 * 2000ms) + 10 error executions before the error is thrown. If retry:true
, the error will never be thrown, because it will keep trying.
Try setting retry: false
on the query level and see if it works. If it works, you probably have to change your default query client configs.