@hono/typebox-validator
Advanced tools
@@ -64,5 +64,12 @@ "use strict"; | ||
| } | ||
| return c.json({ success: false, errors: [...value_1.Value.Errors(schema, data)] }, 400); | ||
| const errors = Array.from(value_1.Value.Errors(schema, data)); | ||
| if (hook) { | ||
| const hookResult = hook({ success: false, errors }, c); | ||
| if (hookResult instanceof Response || hookResult instanceof Promise) { | ||
| return hookResult; | ||
| } | ||
| } | ||
| return c.json({ success: false, errors }, 400); | ||
| }); | ||
| } | ||
| exports.tbValidator = tbValidator; |
@@ -61,4 +61,11 @@ import { Value } from '@sinclair/typebox/value'; | ||
| } | ||
| return c.json({ success: false, errors: [...Value.Errors(schema, data)] }, 400); | ||
| const errors = Array.from(Value.Errors(schema, data)); | ||
| if (hook) { | ||
| const hookResult = hook({ success: false, errors }, c); | ||
| if (hookResult instanceof Response || hookResult instanceof Promise) { | ||
| return hookResult; | ||
| } | ||
| } | ||
| return c.json({ success: false, errors }, 400); | ||
| }); | ||
| } |
+1
-1
| { | ||
| "name": "@hono/typebox-validator", | ||
| "version": "0.2.4", | ||
| "version": "0.2.5", | ||
| "description": "Validator middleware using TypeBox", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
7952
7%208
7.22%