Skip to content

Commit

Permalink
Update ERROR_HANDLING.md (#2022)
Browse files Browse the repository at this point in the history
Makes the example more consistent with the provided explanations above as well as increasing the clarity of the example. Can for example be easy to miss that you need to name the error map variable exactly the same as the property field when passing it this way.
  • Loading branch information
SimonProper committed Feb 27, 2023
1 parent 75cb9e8 commit c4d4e49
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ERROR_HANDLING.md
Expand Up @@ -232,7 +232,7 @@ Let's look at a practical example of of customized error map:
```ts
import * as z from "zod";

const errorMap: z.ZodErrorMap = (error, ctx) => {
const customErrorMap: z.ZodErrorMap = (error, ctx) => {
/*
This is where you override the various error codes
*/
Expand All @@ -257,7 +257,7 @@ const errorMap: z.ZodErrorMap = (error, ctx) => {
return { message: ctx.defaultError };
};

z.string().parse(12, { errorMap });
z.string().parse(12, { errorMap: customErrorMap });

/* throws:
ZodError {
Expand Down

0 comments on commit c4d4e49

Please sign in to comment.