@@ -8,10 +8,10 @@ import { buildResultInvalidRequest } from "@ensnode/ensnode-sdk";
88import { resultIntoHttpResponse } from "@/lib/result/result-into-http-response" ;
99
1010/**
11- * Creates a Hono validation middleware with custom error formatting .
11+ * Creates a Hono validation middleware.
1212 *
13- * Wraps the Hono validator with custom error handling that uses the
14- * errorResponse function for consistent error formatting across the API.
13+ * Wraps the Hono validator with custom error handling that uses standardized
14+ * response data model across the API.
1515 *
1616 * @param target - The validation target (param, query, json, etc.)
1717 * @param schema - The Zod schema to validate against
@@ -22,12 +22,13 @@ export const validate = <T extends ZodType, Target extends keyof ValidationTarge
2222 schema : T ,
2323) =>
2424 validator ( target , schema , ( result , c ) => {
25- // if validation failed, return our custom-formatted ErrorResponse instead of default
25+ // Respond with the invalid request result if validation failed.
2626 if ( ! result . success ) {
2727 // Convert Standard Schema issues to ZodError for consistent formatting
2828 const schemaError = new SchemaError ( result . error ) ;
2929 const zodError = new ZodError ( schemaError . issues as ZodError [ "issues" ] ) ;
30+ const errorMessage = prettifyError ( zodError ) ;
3031
31- return resultIntoHttpResponse ( c , buildResultInvalidRequest ( prettifyError ( zodError ) ) ) ;
32+ return resultIntoHttpResponse ( c , buildResultInvalidRequest ( errorMessage ) ) ;
3233 }
3334 } ) ;
0 commit comments