We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When the verification fails, can Zod Validator throw an exception instead of directly returning an error message?
The text was updated successfully, but these errors were encountered:
You can use the middleware for this. honojs/hono#960
Sorry, something went wrong.
This can be handled by a wrapper function:
import {z, ZodSchema} from "zod"; import type {ValidationTargets} from "hono"; import {zValidator as zv} from "@hono/zod-validator"; export const zValidator = < T extends ZodSchema, Target extends keyof ValidationTargets, >( target: Target, schema: T, ) => zv(target, schema, (result, c) => { if(!result.success) { throw result.error } })
or another version that supports a custom hook
import {z, ZodSchema} from "zod"; import type { ValidationTargets, Env } from "hono"; import { zValidator as zv , type Hook} from "@hono/zod-validator"; export const zValidator = < T extends ZodSchema, Target extends keyof ValidationTargets, E extends Env, P extends string >( target: Target, schema: T, hook: Hook<z.infer<T>, E, P, Target> = (result, _c) => { if(!result.success) throw result.error } ) => zv(target, schema, hook)
zErrValidator
docs(zod-validator): add usage docs for zErrValidator, throw a vali…
4b665d3
…dating error instead of directly returning an error response. (honojs#890)
Successfully merging a pull request may close this issue.
When the verification fails, can Zod Validator throw an exception instead of directly returning an error message?
The text was updated successfully, but these errors were encountered: