mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 19:28:17 +00:00
fix: onboarding validation
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user