This commit is contained in:
2025-09-11 19:47:33 -04:00
parent 317da3aaf7
commit c2eb111291
14 changed files with 217 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ import type { MiddlewareHandler } from "@hono/hono";
import { z } from "zod";
import type { HonoEnv } from "./types.ts";
import { ZodSchema } from "zod/v4";
import { HTTPStatus } from "@oneday/http-status";
// thanks claude, this hurt my brain!
@@ -11,9 +12,16 @@ export const typedZValidator = <
S extends ZodSchema
>(
target: T,
schema: S
schema: S,
httpOk?: boolean,
recNetError?: string
) => {
return zValidator(target, schema) as MiddlewareHandler<
return zValidator(target, schema, (result, c) => {
if (!result.success) {
if (recNetError) return c.json({ success: false, error: recNetError }, httpOk == true ? HTTPStatus.OK : HTTPStatus.BadRequest);
else return c.json({ success: false, error: "Request validation failed" }, httpOk == true ? HTTPStatus.OK : HTTPStatus.BadRequest);
}
}) as MiddlewareHandler<
HonoEnv,
string,
{