-
Notifications
You must be signed in to change notification settings - Fork 101
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
validating all parts of the request #433
Comments
Hi @ryanleecode
Hono's Validator validates the specified content, param, header, query, etc. By sequential, do you mean when use multiple validators? In that case, how about using a custom Hook? app.get(
'/posts/:id',
zValidator(
'param',
z.object({
id: z.coerce.number()
}),
(result, c) => {
if (!result.success) {
return c.json(
{
'error in': 'param'
},
400
)
}
}
),
zValidator(
'query',
z.object({
page: z.coerce.number()
}),
(result, c) => {
if (!result.success) {
return c.json(
{
'error in': 'query'
},
400
)
}
}
),
(c) => {
const { page } = c.req.valid('query')
// ...
return c.json({
})
}
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
zod validation is sequential right now. Meaning if the headers are invalid it will fail-first and not return any information about other parts of the request that might be invalid. Also the zod error has no context about the origin. you cant tell if its from header, query, body, etc by default.
The text was updated successfully, but these errors were encountered: