mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 21:50:57 +00:00
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.
This commit is contained in:
17
apps/edr-freight-web/backoffice/src/utils/errorExtractor.ts
Normal file
17
apps/edr-freight-web/backoffice/src/utils/errorExtractor.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
Reference in New Issue
Block a user