Type safe errors?
Hi, it's there a way to make something like this in Trpc?
The idea is to get also the query.error prop also type safe based on the output of the procedure
3 Replies
errorFormatter is what you want
Almost, but not quite there. For example, if a procedure requires some authentication, then in the error prop something like "AUTHENTICATION_ERROR", if the procedure also needs to validate permissions, then the error should be like "AUTHENTICATION_ERROR" | "MISSING_PERMISSIONS".
With the errorFormatter, these errors will be on every procedure even if the procedure doesn't procedure them
Yes you should be throwing sensible errors that you can handle later
The formatter just sets the shape / union of types.