Handling errors on the front-end
I'm making a mutation from my front-end and I intentionally throw a new TRPCError on my backend, I can see the trpc error on both client and server console but I don't understand how to catch it in the front-end
The mutation onError does nothing, myMutation.isError is false, myMutation.error is null and status "idle"
Here's some example code
And then on my code
How I throw the error
I also tried this
Pretty sure I'm just missing something here so a little help would be appreciated, thank you!
7 Replies
If it’s not reaching the frontend then most likely your backend isn’t actually throwing the error, or some middleware is swallowing it
Check the API-side onError and errorFormatter callbacks are receiving it
I can see it on my frontend console
Server-side onError receives it as well as the error formatter
But as you can see on the image all the error values are false/null
I looked through all the files but can't seem to find something that swallows it @nlucas
Okay yeah it’s sending a 500 back so looks like that’s fine
It looks like it should be calling the useMutation callback right now
To catch imperatively you should await mutateAsync though
Even that doesn't work, I'm sorry but I can't see what I am missing here and why throwing an error from the server is so difficult to handle on the client. All of the tRPC settings and files are default and I haven't changed any error formatters or loggerlinks or whatever, should I post a git issue for this maybe?
Post your trpc & react-query instantiation code on the client
On my _app.tsx
export default api.withTRPC(MyApp);
The api file
Also previously when I mentioned that settings are default I mean the default t3 stack configuration
@s.daniel Let me know if you need anything else