2026-07-17 10:45:59 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-07 20:48:30 -03:00
|
|
|
|
2026-09-16 11:17:37 -03:00
|
|
|
export const DISPATCH_REQUIRED_MESSAGE = "Select a vendor company before saving.";
|
|
|
|
|
|
2026-09-07 20:48:30 -03:00
|
|
|
/** why: backend field names must never be exposed through user-facing board toasts. */
|
|
|
|
|
export function boardPatchValidationMessage(error: BoardPatchValidationError): string {
|
|
|
|
|
if (error.code === "DispatchRequired") {
|
2026-09-16 11:17:37 -03:00
|
|
|
return DISPATCH_REQUIRED_MESSAGE;
|
2026-09-07 20:48:30 -03:00
|
|
|
}
|
|
|
|
|
return error.message;
|
|
|
|
|
}
|