woah man
This commit is contained in:
@@ -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,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user