functiondjF
tRPC12mo ago
2 replies
functiondj

How can i check if an error is a TRPC Error in the browser?

error.message // NOT_FOUND (throwing this intentionally - i'd like to build a react error boundary that has specific handling for TRPC Errors like NOT_FOUND)
Object.getPrototypeOf(error) // default "Error" object/class
error instanceof TRPCClientError // false. this would have been my best bet.
Solution
It is often useful to access the types of your API within your clients. For this purpose, you are able to infer the types contained in your AppRouter.
Inferring Types | tRPC
Was this page helpful?