Replies: 1 comment
|
You don't need brittle substring matching for this, and there is a clean architectural reason why Why
|
|
You don't need brittle substring matching for this, and there is a clean architectural reason why Why
|
Uh oh!
There was an error while loading. Please reload this page.
I'd like to be able to differentiate between custom errors and default error messages that originated from zod itself.
I translate all zod error manually to make them a bit more user friendly. I've written a function that unpacks the $ZodIssue
and renders custom error message by looking at the shape of ZodIssue, which is currently defined as:
{ "origin": "array", "code": "too_small", "minimum": 1, "inclusive": true, "path": [ "name" ], "message": "A pokemon must be at least part of one type" }It came from the following configuration:
Now I'd like to be able to differentiate between default zod error messages such as
"Too small: expected string to have >=1 characters"and explicit programmer / developer provided ones such as the "pokemon types" errors above.Would it be possible (and is it a a good idea?) to extend $ZodIssue with a boolean:
customMessage.When
customMessageistrueit was an error param provided by the developer, whenfalseit came from zod.Currently I'm forced to solve this via the following hack:
Of course the above code is brittle: if a developer passed in 'Too small: A pokemon must be at least part of one type' it will break.
Maybe there already exists an API to check this in zod I have not found it, please let me know.
All reactions