mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
- 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.
18 lines
853 B
TypeScript
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;
|
|
};
|