pupoP
tRPC6mo ago
1 reply
pupo

how to handle non-trpc errors?

I'm using supabase, and other custom errors within my trpc procedures. The errors thrown are all converted to TRPC errors INTERNAL_SERVER_ERROR, when some of these errors should be converted to other type of TRPC errors. How can i manage this ?

I tried the onError handler, but its too late at this point. the error is already a TRPC error. I tried using a middleware as well, but the errors throw are not caught by the middleware.

The only reference I've found in the docs is here:
https://trpc.io/docs/server/error-handling

but this assumes you are throwing all the errors as TRPC errors from the get go.

Any ideas would be very welcomed!
Whenever an error occurs in a procedure, tRPC responds to the client with an object that includes an "error" property. This property contains all the information that you need to handle the error in the client.
Error Handling | tRPC
Was this page helpful?