Function: translateAnthropicError()
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:191
Classify an error thrown by the Anthropic SDK into an ADK disposition.
Parameters
| Parameter | Type | Description |
|---|---|---|
err | unknown | The thrown value. |
retriableStatuses | readonly 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
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.
Branch coverage for real SDK error shapes (issue #46): an abort (APIUserAbortError), a request timeout (APIConnectionTimeoutError, the APIConnectionError subclass the SDK throws on its own deadline), a transport failure (APIConnectionError, retriable at status 0), any HTTP-status error (an APIError carrying status and Headers) whose subclasses are matched through the same structural walk, and finally a non-HTTP SDK failure (AnthropicError, e.g. a RetryableError) or any other thrown value — both fatal at status 0.