mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
31 lines
1009 B
TypeScript
31 lines
1009 B
TypeScript
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" };
|
|
}
|