Error Handling vs Error Formatting
I'm a bit confused from the docs about how I should be handling errors on the server. The Error Handling section refers to handling errors client side right?
More specifically, the ORM I'm using suggests delegating error handling to the server implementation. Where the ORM is throwing an instance of its internal
NotFoundError
class, I need to update the response http code to 404 and also hide the data associated with that error in production. Should I be doing this within the errorFormatter
?
Thanks!3 Replies
e.g. I could do something like this, but I'm sure there is a better way? Like throwing a
new TRPCError
somewhere internally between my procedure and the formatter?
Where the ORM is throwing an instance of its internal NotFoundError class, I need to update the response http code to 404 and also hide the data associated with that error in production. Should I be doing this within the errorFormatter?Yes I think you're doing it all right If you need to handle errors on the server, you can use a middleware to catch the DB's errors and then do whatever you need, then rethrow if you want the error to reach the frontend
Great, thanks for clarifying!