zomarsZ
tRPC4y ago
12 replies
zomars

Zod Error Middleware

Hey lovely people. At Cal.com we make heavy use of
zod
for data validation. I was wondering if there's a way to create some kind of "error middleware" that can catch all Zod specific errors and serve the proper TRPC error back to the client.

This would allow us to just use
schema.parse
instead of having to manually check
schema.safeParse
or having to use
try/catch
everywhere.

Thanks for any input! 🙏
Was this page helpful?