diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts index 24c3416..650497a 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts @@ -144,7 +144,7 @@ `[VALIDATION ERROR] ${req.method} ${req.originalUrl} - SCHEMA='${opts.requestBody}' -`, validate?.errors, ); - throw FieldErrors(fields); + throw FieldErrors(fields, validate.errors!); } } next(); diff --git a/src/util/util/FieldError.ts b/src/util/util/FieldError.ts index f1976d3..a99a048 100644 --- a/src/util/util/FieldError.ts +++ b/src/util/util/FieldError.ts @@ -16,6 +16,8 @@ along with this program. If not, see . */ +import { ErrorObject } from "ajv"; + export interface FieldErrorResponse { code: number; message: string; @@ -25,7 +27,7 @@ export type ErrorContent = { code: string; message: string }; export type ObjectErrorContent = { _errors: ErrorContent[] }; -export function FieldErrors(fields: Record) { +export function FieldErrors(fields: Record, errors?: ErrorObject[]) { return new FieldError( 50035, "Invalid Form Body", @@ -37,6 +39,7 @@ }, ], })), + errors ); } @@ -48,6 +51,7 @@ public code: string | number, public message: string, public errors?: object, // TODO: I don't like this typing. + public _ajvErrors?: ErrorObject[] ) { super(message); }