(fix) return 429 error

This commit is contained in:
ishaan-jaff 2024-03-13 08:03:28 -07:00
parent aaa008ecde
commit 3aeada232e

View file

@ -171,6 +171,15 @@ class ProxyException(Exception):
self.param = param self.param = param
self.code = code self.code = code
# rules for proxyExceptions
# Litellm router.py returns "No healthy deployment available" when there are no deployments available
# Should map to 429 errors https://github.com/BerriAI/litellm/issues/2487
if (
"No healthy deployment available" in self.message
or "No deployments available" in self.message
):
self.code = 429
def to_dict(self) -> dict: def to_dict(self) -> dict:
"""Converts the ProxyException instance to a dictionary.""" """Converts the ProxyException instance to a dictionary."""
return { return {
@ -2907,10 +2916,7 @@ async def chat_completion(
param=getattr(e, "param", "None"), param=getattr(e, "param", "None"),
code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST),
) )
else: error_msg = f"{str(e)}"
error_traceback = traceback.format_exc()
error_msg = f"{str(e)}\n\n{error_traceback}"
raise ProxyException( raise ProxyException(
message=getattr(e, "message", error_msg), message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"), type=getattr(e, "type", "None"),