Skip to content
1 min read · 213 words

Function: translateAnthropicError()

ts
function translateAnthropicError(
  err: unknown,
  retriableStatuses: readonly number[],
  opts?: {
    resolveErrorStatus?: AnthropicMessagesErrorStatusResolver;
    warn?: (msg: string) => void;
  },
): AnthropicErrorClassification;

Defined in: src/batteries/llm/anthropic_messages/error_translation.ts:120

Classify an error thrown by the Anthropic SDK into an ADK disposition.

Parameters

ParameterTypeDescription
errunknownThe thrown value.
retriableStatusesreadonly number[]Status codes configured as retriable.
opts?{ resolveErrorStatus?: AnthropicMessagesErrorStatusResolver; warn?: (msg: string) => void; }Optional status resolver and warning sink.
opts.resolveErrorStatus?AnthropicMessagesErrorStatusResolver-
opts.warn?(msg: string) => void-

Returns

AnthropicErrorClassification

The classification.

Remarks

Ordering is deliberate. Abort and timeout are checked first because they are control-flow outcomes rather than failures. APIConnectionError is retriable at status 0 — a transport fault has no HTTP status and never will, and that branch establishes the convention that a statusless error can still be retriable.

For an APIError, the consumer's resolveErrorStatus hook (when configured) runs BEFORE both the context-overflow check and retriable classification, so a recovered status participates in every downstream decision and is what gets reported — a recovered 529 surfaces as 529, not 0. Without a resolver the behaviour is unchanged from before the hook existed: a statusless APIError coerces to 0, matches no retriable status, and is fatal.