TkDodo ๐Ÿ”ฎT
tRPCโ€ข4y agoโ€ข
17 replies
TkDodo ๐Ÿ”ฎ

Error handling

We have some trpc routers that make requests to another api - we use axios for that. I'd like to forward these errors to the frontend, so if that api errors with 401, that's what I'd like to see in the browser.
If I just await the request and don't catch the errors, I get a 500 error where the message is the message from the axios request.
What would be the best way to handle this, globally? I wouldn't really want to wrap each api in a try / catch, and I'd also ideally not need to translate those errors to TRPCErrors...
Was this page helpful?