tRPCttRPC
Powered by
zomarsZ
tRPC•4y ago•
12 replies
zomars

Zod Error Middleware

Hey lovely people. At Cal.com we make heavy use of
zod
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
schema.parse
instead of having to manually check
schema.safeParse
schema.safeParse
or having to use
try/catch
try/catch
everywhere.

Thanks for any input! 🙏
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Zod formatting Error
Nacho EliasNNacho Elias / ❓-help
2y ago
Error calling middleware
bill92Bbill92 / ❓-help
2y ago
Zod error not being formatted
Nacho EliasNNacho Elias / ❓-help
2y ago
Usage with zod-validation-error
jlarmstJjlarmst / ❓-help
3y ago