Uecko_ERP/modules/customers/src/api/infrastructure/express/customer-api-error-mapper.ts

17 lines
679 B
TypeScript

import { ApiErrorMapper, ErrorToApiRule, NotFoundApiError } from "@erp/core/api";
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) =>
new NotFoundApiError(
(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);