Include full AJV error on api

This commit is contained in:
Rory& 2025-10-17 03:44:08 +02:00
parent 95d13499d4
commit c41c3c068e
2 changed files with 6 additions and 2 deletions

View File

@ -144,7 +144,7 @@ export function route(opts: RouteOptions) {
`[VALIDATION ERROR] ${req.method} ${req.originalUrl} - SCHEMA='${opts.requestBody}' -`, `[VALIDATION ERROR] ${req.method} ${req.originalUrl} - SCHEMA='${opts.requestBody}' -`,
validate?.errors, validate?.errors,
); );
throw FieldErrors(fields); throw FieldErrors(fields, validate.errors!);
} }
} }
next(); next();

View File

@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { ErrorObject } from "ajv";
export interface FieldErrorResponse { export interface FieldErrorResponse {
code: number; code: number;
message: string; message: string;
@ -25,7 +27,7 @@ export interface FieldErrorResponse {
export type ErrorContent = { code: string; message: string }; export type ErrorContent = { code: string; message: string };
export type ObjectErrorContent = { _errors: ErrorContent[] }; export type ObjectErrorContent = { _errors: ErrorContent[] };
export function FieldErrors(fields: Record<string, { code?: string; message: string }>) { export function FieldErrors(fields: Record<string, { code?: string; message: string }>, errors?: ErrorObject[]) {
return new FieldError( return new FieldError(
50035, 50035,
"Invalid Form Body", "Invalid Form Body",
@ -37,6 +39,7 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
}, },
], ],
})), })),
errors
); );
} }
@ -48,6 +51,7 @@ export class FieldError extends Error {
public code: string | number, public code: string | number,
public message: string, public message: string,
public errors?: object, // TODO: I don't like this typing. public errors?: object, // TODO: I don't like this typing.
public _ajvErrors?: ErrorObject[]
) { ) {
super(message); super(message);
} }