2025-11-06 16:17:00 +00:00
|
|
|
import { ApiErrorMapper, ErrorToApiRule, NotFoundApiError } from "@erp/core/api";
|
2025-10-04 16:29:14 +00:00
|
|
|
import { CustomerNotFoundError, isCustomerNotFoundError } from "../../domain";
|
|
|
|
|
|
|
|
|
|
// Crea una regla específica (prioridad alta para sobreescribir mensajes)
|
|
|
|
|
const customerNotFoundRule: ErrorToApiRule = {
|
|
|
|
|
priority: 120,
|
|
|
|
|
matches: (e) => isCustomerNotFoundError(e),
|
|
|
|
|
build: (e) =>
|
2025-11-06 16:17:00 +00:00
|
|
|
new NotFoundApiError(
|
2025-10-04 16:29:14 +00:00
|
|
|
(e as CustomerNotFoundError).message || "Customer with the provided id not exists."
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Cómo aplicarla: crea una nueva instancia del mapper con la regla extra
|
|
|
|
|
export const customersApiErrorMapper: ApiErrorMapper =
|
|
|
|
|
ApiErrorMapper.default().register(customerNotFoundRule);
|