Use the default error hook in OpenAPIHono
mainYou can include defaultHook from stoker/openapi/default-hook in your OpenAPIHono instance. This hook automatically handles validation errors by responding with a 422 Unprocessable Entity status code and a JSON body containing a success: false flag and the full ZodError object.
import { OpenAPIHono } from "@hono/zod-openapi";
import defaultHook from "stoker/openapi/default-hook";
/*
Any validation errors will respond with status code 422 and body:
{
success: false,
error: {}, // Full Zod Error
}
*/
const app = new OpenAPIHono({
defaultHook,
});
export default app;