/** * Pull the SERVER's actual error message out of a failed request. * * NestJS returns `{ message: string | string[] }`; a class-validator failure is * the array form (joined here). Falls back to the error's own `.message` — the * axios response interceptor (see `auth/http.ts`) already rewrites that to the * server message, so even code paths that never see the raw response body get * the real cause — then to the caller's fallback string. */ export const extractErrorMessage = (err: unknown, fallback: string): string => { const msg = (err as { response?: { data?: { message?: string | string[] } } }) ?.response?.data?.message; if (Array.isArray(msg)) return msg.filter(Boolean).join(", "); if (typeof msg === "string" && msg) return msg; if (err instanceof Error && err.message) return err.message; return fallback; };