-
Notifications
You must be signed in to change notification settings - Fork 292
feat: customizable validation errors #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Oh, is it normal that we have a |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Deploying h3dev with
|
| Latest commit: |
9f96225
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://69c3837d.h3dev.pages.dev |
| Branch Preview URL: | https://feat-custom-validation-error.h3dev.pages.dev |
| age: v.pipe(v.number(), v.integer(), v.minValue(1)), | ||
| }), | ||
| { | ||
| onError: (issues) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can input be in { issues } format (or we pass whole result to format error?
Both for forward compatibility and also support custom errors
resolves #982
I've added an additional argument to each
readValidatedBody,getValidatedQueryandgetValidatedRouteParamswhich can be either an error object or a function that returns one. If a standard-schema is being used, then theissuesarray is available as an argument for the function variant.This allows for the following custom error, which will ouput a markdown list of all the errors recorded:
I've also updated the
defineValidatedHandler, which brings three more properties:bodyErrors,headersErrorsandqueryErrors. All allowing for either error object or function that returns oneAdded two types, but I'm not super satisfied with
ValidateIssuesnaming (I'm open for suggestions):I've also made sure that if a
new HTTPErroris thrown during validation, its content will be directly passed as is, quite useful for non-standard-schema validations.