Status code used in the third argument of zValidator is not inferred on the client side
I have the following code. When trying to handle branching on the client side based on res.status, it always ends up being 200. Is there any documentation or solution regarding this issue?
const sampleRoute = new Hono().get(
'/sample',
zValidator(
'json',
z.object({
keyword: z.string().min(1),
}),
(result, c) => {
if (!result.success) {
return c.json({ error: 'error!' }, 400)
}
}
),
async (c) => {
return c.json({ data: 'data' }, 200)
}
)
in client
I am also noticing the client type doesn't have the 400 response code without the third argument when using valibot.
Hi @mayone-du
Thank you for the issue. This should be fixed. But we need time since it is a little difficult.
@NamesMT Can you also take a look if you have time?
Hi @yusukebe,
Currently MiddlewareHandler's Inputs is not taken to account for the final TypedResponse output in HandlerInterface flow, as well as the Input interface for middlewares does not have a way to pass status code along with it yet.
So, we need:
- A way for middlewares to pass along the status code in type,
- Taken account of all
Input['out']for the final response, this could be done mainly atToSchemalevel and/or theHandlerInterfaceI think.
I don't have much time to work on it yet, I'll start a draft PR when I do.
honojs/hono#2719