fix(bedrock.py): add exception mapping coverage for authentication scenarios

This commit is contained in:
Krrish Dholakia 2023-11-03 18:25:34 -07:00
parent 142750adff
commit 1c4dd0671b
3 changed files with 29 additions and 8 deletions

View file

@ -2946,14 +2946,14 @@ def exception_type(
model=model,
llm_provider="bedrock"
)
if "Unable to locate credentials" in error_str or "Malformed input request" in error_str:
if "Malformed input request" in error_str:
exception_mapping_worked = True
raise InvalidRequestError(
message=f"BedrockException - {error_str}",
model=model,
llm_provider="bedrock"
)
if "The security token included in the request is invalid" in error_str:
if "Unable to locate credentials" in error_str or "The security token included in the request is invalid" in error_str:
exception_mapping_worked = True
raise AuthenticationError(
message=f"BedrockException Invalid Authentication - {error_str}",
@ -2975,6 +2975,13 @@ def exception_type(
llm_provider="bedrock",
model=model
)
elif original_exception.status_code == 401:
exception_mapping_worked = True
raise AuthenticationError(
message=f"BedrockException - {original_exception.message}",
llm_provider="bedrock",
model=model
)
elif custom_llm_provider == "sagemaker":
if "Unable to locate credentials" in error_str:
exception_mapping_worked = True