How to map internal errors to TRPCError types?
Hi, my application is throwing it's own set of custom Errors.
Unfortunatelly tRPC always catch this errors and represent them as UNEXPECTED_SERVER_ERROR type.
I tried following:
I ended up wrapping all of my mutation/query handlers in following function:
I just wanted to ask if there isn't better way of doing this - eg. I believe this is exactly what middleware is supposed to do - apply code per each handler so you don't need to.
How can I get anything else than TRPCError in middleware?
1 Reply
So tRPC has errorFormatter which you can use globally
Otherwise throwing tRPC errors at the procedure level is good when you want to include a specific status code
For handling errors in the client using the errorFormatter is good because its type-safe though you don’t need to worry about the status code so much since it’s just typescript