Throw custom TRPCError with specific cause
Hello everyone !
I'm trying to throw a custom TRPCError with a specific cause that i can differentiate from other trpc errors. My use case is to be able to catch error on client and display an error message if the error code is 'BAD_REQUEST' and a specific cause. After investigating i find that something like this should work in my mutation procedure:
But in my errorFormatter i only receive this object cause field is not present.
Can someone enlighten me on how to solve this problem ?
Thanks 🙂
2 Replies
Ok, i find the problem, cause has to be an Error so i replace the code with this:
I'm experiencing the same thing. If I throw an error on the server, something like this:
If I catch the error on the server, the cause is there. But in my errorFormatter, it is no longer present. Is the cause supposed to be present on the client side when using superjson?
Ok, it was available in the error formatter when checking the error object. I only checked the shape and the output of the formatter. It seems you need to change the shape to include the cause. Is this intended behavior or some error on my end?