fix(gateway): improve validation errors (#1347)

Thanks @vignesh07.

Co-authored-by: Vignesh <vignesh07@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-21 02:28:15 +00:00
parent daceeaa24c
commit 9d7087168f
3 changed files with 74 additions and 3 deletions

View File

@@ -310,7 +310,7 @@ export const validateWebLoginStartParams =
export const validateWebLoginWaitParams = ajv.compile<WebLoginWaitParams>(WebLoginWaitParamsSchema);
export function formatValidationErrors(errors: ErrorObject[] | null | undefined) {
if (!errors) return "unknown validation error";
if (!errors?.length) return "unknown validation error";
const parts: string[] = [];
@@ -328,13 +328,18 @@ export function formatValidationErrors(errors: ErrorObject[] | null | undefined)
}
}
const message = typeof err?.message === "string" ? err.message : "validation error";
const message =
typeof err?.message === "string" && err.message.trim() ? err.message : "validation error";
const where = instancePath ? `at ${instancePath}: ` : "";
parts.push(`${where}${message}`);
}
// De-dupe while preserving order.
const unique = Array.from(new Set(parts));
const unique = Array.from(new Set(parts.filter((part) => part.trim())));
if (!unique.length) {
const fallback = ajv.errorsText(errors, { separator: "; " });
return fallback || "unknown validation error";
}
return unique.join("; ");
}