import { CbeFailureClass } from "../entities/cbe-bill-operation.entity"; /** * A CBE business/transport outcome we detected ourselves. `failureClass` drives the §6.5 * same-End_To_End_Txn_Id retry policy: BUSINESS outcomes are final (retrying cannot change * the answer), TRANSIENT ones (our 5xx, domain app unreachable) may be retried by CBE. */ export class CbeBillError extends Error { constructor( message: string, readonly failureClass: CbeFailureClass, ) { super(message); this.name = "CbeBillError"; } } /** * Every failure maps to Response_Code "2" (per current CBE integration requirement; the * original AAFDA plan used 3); only the description is specific (plan §6.6). */ export function toCbeFailure(err: unknown): { description: string; failureClass: CbeFailureClass; } { if (err instanceof CbeBillError) { return { description: err.message, failureClass: err.failureClass }; } return { description: "Internal error", failureClass: "TRANSIENT" }; }