mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 01:33:12 +00:00
Board create failures toasted the backend message verbatim, exposing field names such as siteCode and vendorId from the inline row and the wizard. Map known codes to product copy and fall back to generic copy for every other failure.
33 lines
1,020 B
TypeScript
33 lines
1,020 B
TypeScript
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
export class BoardPatchConflictError extends Error {
|
|
readonly status = 409;
|
|
readonly currentState: WorkOrderTableRow | null;
|
|
|
|
constructor(message: string, currentState: WorkOrderTableRow | null) {
|
|
super(message);
|
|
this.name = "BoardPatchConflictError";
|
|
this.currentState = currentState;
|
|
}
|
|
}
|
|
|
|
export class BoardPatchValidationError extends Error {
|
|
readonly status = 422;
|
|
readonly code: string;
|
|
|
|
constructor(code: string, message: string) {
|
|
super(message);
|
|
this.name = "BoardPatchValidationError";
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
export const DISPATCH_REQUIRED_MESSAGE = "Select a vendor company before saving.";
|
|
|
|
/** why: backend field names must never be exposed through user-facing board toasts. */
|
|
export function boardPatchValidationMessage(error: BoardPatchValidationError): string {
|
|
if (error.code === "DispatchRequired") {
|
|
return DISPATCH_REQUIRED_MESSAGE;
|
|
}
|
|
return error.message;
|
|
}
|