fix: onboarding validation

This commit is contained in:
Nathnael
2026-08-06 18:54:54 +00:00
parent ab7069e335
commit dd2b624aa6
11 changed files with 804 additions and 165 deletions

View File

@@ -34,6 +34,16 @@ function humanizeApiMessage(raw: string): string {
return raw;
}
/**
* NestJS's ValidationPipe reports every failed constraint at once, so `message`
* arrives as a string[] rather than a string. Flatten it — passing the array
* through left the UI rendering its entries run together with no separator.
*/
function asMessage(value: unknown): string {
if (Array.isArray(value)) return value.filter(Boolean).join(". ");
return typeof value === "string" ? value : "";
}
export function extractApiError(err: unknown): ApiError {
if (err && typeof err === "object") {
const obj = err as Record<string, unknown>;
@@ -41,13 +51,10 @@ export function extractApiError(err: unknown): ApiError {
if (response) {
const statusCode = response.status as number | undefined;
const data = response.data as Record<string, unknown> | undefined;
const raw = asMessage(data?.message) || asMessage(data?.error);
return {
code: (data?.message as string) || (data?.error as string) || "api_error",
message: humanizeApiMessage(
(data?.message as string) ||
(data?.error as string) ||
"An unexpected error occurred",
),
code: raw || "api_error",
message: humanizeApiMessage(raw || "An unexpected error occurred"),
statusCode,
};
}