Catch TRPCError, ZoddError on the front-end
i am throwing a TRPCError in a mutation. i dont understand how to catch this error in the OnError method. Please help me with this.
i have the following:
ServerSide
ClientSide
everyting is undefined except for message. but i'd like to include ZodError to the cause. doesn't work either.
browser console.
9 Replies
the console.log inside the if statement doesnt get printed
Add the actual zod error as the cause in the trpc error instead
Then use error.cause
errors.cause is undefined when on client
On the client? If you want to propagate to the client you need error formatting
Error Formatting | tRPC
The error formatting in your router will be inferred all the way to your client (&Β ReactΒ components)
And it'll be a TRPCClientError
to want to catch the zod parse error, you actually have to throw a zodError
should be included in the docs in my opinion
also dont flatten the error when formatting
also dont safparse
feel free to improve the docs! π would love some help!
none of the people working on trpc does it as a full-time job
Good to know! (The first part I mean, I knew the second part)