Skip to content

Function: termRefusalOf()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / termRefusalOf

termRefusalOf(error): TermRefusal | undefined

Defined in: src/utils/term-refusal.ts:118

Read the refusal of a term write from the error the SDK threw for it.

unknown

What a catch received.

TermRefusal | undefined

The refusal — status, code, message, the term, its referrers, the repairs, the rules that hold it and the rule that derived it — or undefined when error is not a term refusal.

Never. Anything that is not a term refusal answers undefined.

The engine’s TermRefusalResponse ({error, code, message, term_id, referrers?, repairs?, rule_ids?, derived_by?}), answered by DELETE and PUT /api/v1/terms/{id} and by POST /api/v1/inference/facts/bulk-retract. A DerivedFactWriteError is one too (code: "write_targets_derived_fact").

The body is the raw wire (snake_case), so every field is read and checked: a body that does not have the shape answers undefined rather than a refusal with holes in it. See TermRefusalCode for every code.

try {
await client.terms.deleteTerm(termId);
} catch (error) {
const refusal = termRefusalOf(error);
if (refusal?.code === 'term_has_referrers') {
console.log(refusal.referrers.map((r) => r.displayName ?? r.termId));
} else throw error;
}