Package com.tnsai.llm.errors
Class BedrockProviderErrorMapper
java.lang.Object
com.tnsai.llm.errors.BedrockProviderErrorMapper
- All Implemented Interfaces:
ProviderErrorMapper
ProviderErrorMapper for AWS Bedrock — sixth pilot mapper.
Bedrock's error envelope uses the standard AWS shape, which comes in two variations across services / endpoints:
// modern shape (most Bedrock APIs)
{ "__type": "ResourceNotFoundException",
"message": "Could not resolve the foundation model from the provided model identifier." }
// legacy XML-derived shape (some older paths)
{ "Code": "ThrottlingException", "Message": "Rate exceeded" }
The mapper tries both — __type → Code → fallback.
Whichever wins, the AWS error code (e.g. ThrottlingException)
is the durable signal; AWS pads it onto multiple HTTP statuses.
Different from the other 5 mappers: not invoked by executeRequest
BedrockClient uses the AWS SDK's
BedrockRuntimeClient.invokeModel, not raw HTTP through
AbstractLLMClient.executeRequest. Mapper invocation is
therefore done at the BedrockClient.chat catch site by
extracting status / body / headers from AwsServiceException
and calling map(int, Map, String, String, Throwable)
directly. The mapper itself doesn't know or care about the SDK —
it sees the same shape as it would over HTTP.
Status routing
ResourceNotFoundException(404) → MODEL_NOT_FOUNDAccessDeniedException(403) /UnrecognizedClientException(401 — invalid AWS creds) → AUTHENTICATION_FAILEDThrottlingException/TooManyRequestsException(429) /ServiceQuotaExceededException→ MODEL_OVERLOADEDValidationException(400) → INVALID_REQUEST, demoted to CONTEXT_TOO_LONG when message hints at token-count overflowModelTimeoutException(408) → SERVER_ERROR (retryable)ServiceUnavailableException(503) → MODEL_OVERLOADED (transient backend pressure)InternalServerException/ModelErrorException/ModelStreamErrorException(500) → SERVER_ERROR- HTTP fallback when no AWS code recognised: 5xx → SERVER_ERROR; 401/403 → AUTHENTICATION_FAILED; 429 → MODEL_OVERLOADED; 4xx → INVALID_REQUEST
Captured headers: x-amzn-requestid,
x-amzn-errortype, retry-after (rare on Bedrock —
AWS prefers exponential backoff via SDK retry config).
- Since:
- 0.5.3 (issue #87 follow-up — sixth pilot mapper)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.exceptions.LLMExceptionmap(int httpStatus, Map<String, String> responseHeaders, String responseBody, String model, Throwable cause) Translate a raw HTTP error response into a typedLLMException.Optional<com.tnsai.exceptions.LLMException.ErrorType> mapErrorType(String providerCode) Map a provider-native error code to a frameworkLLMException.ErrorType.
-
Constructor Details
-
BedrockProviderErrorMapper
public BedrockProviderErrorMapper()
-
-
Method Details
-
providerId
- Specified by:
providerIdin interfaceProviderErrorMapper- Returns:
- short, lowercase provider id (e.g.
"openai","anthropic"). Used to route a raw response to the right mapper.
-
map
public com.tnsai.exceptions.LLMException map(int httpStatus, Map<String, String> responseHeaders, String responseBody, String model, Throwable cause) Description copied from interface:ProviderErrorMapperTranslate a raw HTTP error response into a typedLLMException.- Specified by:
mapin interfaceProviderErrorMapper- Parameters:
httpStatus- HTTP status code from the responseresponseHeaders- selected response headers (lower-cased keys); empty map if none capturedresponseBody- raw response body; mapper parses provider-specific envelope (e.g. JSONerror.code)model- model identifier from the request, for the resultingLLMException.getModel()cause- underlying transport throwable, may be null when the failure is purely a non-2xx response- Returns:
- typed
LLMExceptionwithProviderDetailsattached
-
mapErrorType
Description copied from interface:ProviderErrorMapperMap a provider-native error code to a frameworkLLMException.ErrorType. Implementations should err on the side ofLLMException.ErrorType.UNKNOWNfor codes they don't recognize so that a new provider error doesn't fail the whole mapping path.- Specified by:
mapErrorTypein interfaceProviderErrorMapper- Parameters:
providerCode- native code (e.g."context_length_exceeded")- Returns:
- matching
LLMException.ErrorType, orOptional.empty()if the mapper has no opinion
-