summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-10-17 03:44:08 +0200
committerRory& <root@rory.gay>2025-10-17 03:44:08 +0200
commitc41c3c068e75fd4f3ac8be8f0e59ee87ae099437 (patch)
tree6e911c29ed633d7e94fc0ae211efb34af34f5168 /src
parentFix proto errors maybe (diff)
downloadserver-ts-c41c3c068e75fd4f3ac8be8f0e59ee87ae099437.tar.xz
Include full AJV error on api
Diffstat (limited to 'src')
-rw-r--r--src/api/util/handlers/route.ts2
-rw-r--r--src/util/util/FieldError.ts6
2 files changed, 6 insertions, 2 deletions
diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts

index 24c3416d..650497a2 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts
@@ -144,7 +144,7 @@ export function route(opts: RouteOptions) { `[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 f1976d39..a99a0486 100644 --- a/src/util/util/FieldError.ts +++ b/src/util/util/FieldError.ts
@@ -16,6 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { ErrorObject } from "ajv"; + export interface FieldErrorResponse { code: number; message: string; @@ -25,7 +27,7 @@ export interface FieldErrorResponse { export type ErrorContent = { code: string; message: string }; 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( 50035, "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 message: string, public errors?: object, // TODO: I don't like this typing. + public _ajvErrors?: ErrorObject[] ) { super(message); }