Skip to content

Function: errorBodyCode()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / errorBodyCode

errorBodyCode(error): string | undefined

Defined in: src/utils/error-code.ts:45

Read the machine-readable code of an error body, when the engine sent one.

unknown

Anything a resource method threw.

string | undefined

The body’s code string, or undefined when the error is not an ApiError or its body carries no string code.

The engine’s CodedErrorResponse is { error, code, message }. error is the status’s reason phrase and lands in ApiError.errorCode; code is the contract a caller branches on when one status answers more than one condition — for example 503 speech_synthesis_not_configured against a 502 for a synthesis sidecar that did not answer, or 403 separation_of_duties (the proposer approving their own sort) against a 403 for a missing Manage grant. The message is for a human and may be reworded; do not branch on it.

The codes the engine documents are typed: Speech.SpeechErrorCode, Sorts.SortApprovalErrorCode, Sorts.SortCreateErrorCode, Terms.TermWriteErrorCode, Documents.DocumentAnalysisErrorCode, Ingestion.WebSearchErrorCode, Ingestion.WebIngestErrorCode, Ingestion.DocumentVersionErrorCode, Ingestion.DlqRetryErrorCode, Reviews.ReviewAddErrorCode, Reviews.ReExtractErrorCode, Analysis.AttributeExplorationErrorCode, Functions.FunctionRefusalCode, Marketplace.MarketplaceErrorCode and Cognitive.AgentBeliefErrorCode.

try {
await client.speech.synthesizeSpeech({ text: 'hello' });
} catch (error) {
if (errorBodyCode(error) === 'speech_synthesis_not_configured') voiceOutput = false;
}