Files
edr-platform/apps/edr-freight-web/backoffice/src/utils/errorExtractor.ts
Marshal 603537a20b add yard distances management to rule engine
- Introduced new yard distances resource with CRUD operations.
- Created migration for yard distances table with necessary constraints.
- Implemented service and repository for yard distances handling.
- Added controller for API endpoints to manage yard distances.
- Updated rule engine configuration to include yard distances.
- Enhanced rule engine resource page to support yard distance selection.
- Updated contracts and train builder pages to handle new yard distance logic.
- Added error handling utility for better error message extraction.
2026-07-21 08:50:50 +00:00

18 lines
853 B
TypeScript

/**
* 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;
};