feat: Response 429 if ThrottlingException (#91)

This commit is contained in:
Zhongsheng Ji
2025-03-10 09:01:33 +08:00
committed by GitHub
parent 283115000a
commit fcfebf9d9d

View File

@@ -178,6 +178,9 @@ class BedrockModel(BaseChatModel):
except bedrock_runtime.exceptions.ValidationException as e:
logger.error("Validation Error: " + str(e))
raise HTTPException(status_code=400, detail=str(e))
except bedrock_runtime.exceptions.ThrottlingException as e:
logger.error("Throttling Error: " + str(e))
raise HTTPException(status_code=429, detail=str(e))
except Exception as e:
logger.error(e)
raise HTTPException(status_code=500, detail=str(e))
@@ -762,6 +765,9 @@ class BedrockEmbeddingsModel(BaseEmbeddingsModel, ABC):
except bedrock_runtime.exceptions.ValidationException as e:
logger.error("Validation Error: " + str(e))
raise HTTPException(status_code=400, detail=str(e))
except bedrock_runtime.exceptions.ThrottlingException as e:
logger.error("Throttling Error: " + str(e))
raise HTTPException(status_code=429, detail=str(e))
except Exception as e:
logger.error(e)
raise HTTPException(status_code=500, detail=str(e))