Lesson

Customize zod Error Messages and Handle zod Errors Effectively

customize zod validation messages, customize zod schema property messages, reuse error maps across different schemas, navigate through zod error objects

Access
Included
Transcript
Needs source

While running zod schema validation agains domain-rich objects, the error message saying that a string is not a number might not be really useful.

Especially, when you need to provide a meaningful feeback to the user, e.g. after they have submitted a form with lots of data.

zod allows to customize messages on a very granular level. We can also extract repeatable customization to zod error maps.

Finally, in order to process an error message further (e.g. display it to the user), we need to handle the zod validation errors effectively. Especially, when a big object validation has failed and we could receive a handful of errors.

That's what we learn in this lesson. 🔥