Skip to content

Function: readCausalRefusal()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / readCausalRefusal

readCausalRefusal(error): CausalRefusal | null

Defined in: src/utils/audit-headers.ts:165

Read a causal refusal out of an error, when it is one.

unknown

Anything a resource method threw.

CausalRefusal | null

The refusal, or null when the error is not a causal refusal.

The engine refuses a causal assertion before the handler runs, with a body of its own shape (no message), so ApiError.message reads only HTTP 400. This reads the body instead:

  • 400 {"error":"unreadable causal header","header","reason"} → { kind: 'unreadable_header', header, reason }
  • 422 {"error":"causal assertion refused","kind","expected","actual"} → { kind: 'assertion_refused', violation, expected, actual }
  • 503 {"error":"audit ledger unavailable for causal pre-flight","reason"} → { kind: 'ledger_unavailable', reason }

violation is the engine’s own snake_case kind; CausalViolationKind lists the ones this SDK knows.

try {
await client.sorts.createSort({ name: 'x' }, { causal: { causedBy: id } });
} catch (error) {
const refusal = readCausalRefusal(error);
if (refusal?.kind === 'assertion_refused') console.log(refusal.violation);
}