mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
Merge 71bf9fe0bb into 2bb7387a83
This commit is contained in:
commit
61611be1af
2 changed files with 31 additions and 2 deletions
|
|
@ -5293,11 +5293,17 @@ def handle_exception_on_proxy(e: Exception) -> ProxyException:
|
|||
)
|
||||
elif isinstance(e, ProxyException):
|
||||
return e
|
||||
original_status_code = getattr(e, "status_code", None)
|
||||
if isinstance(original_status_code, int) and 400 <= original_status_code < 600:
|
||||
error_code = original_status_code
|
||||
else:
|
||||
error_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
return ProxyException(
|
||||
message="Internal Server Error, " + str(e),
|
||||
message=getattr(e, "message", str(e)),
|
||||
type=ProxyErrorTypes.internal_server_error,
|
||||
param=getattr(e, "param", "None"),
|
||||
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
code=error_code,
|
||||
headers=getattr(e, "headers", None),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -190,3 +190,26 @@ def test_get_projected_spend_over_limit_includes_current_spend(monkeypatch):
|
|||
projected_spend, projected_exceeded_date = result
|
||||
assert projected_spend == 290.0
|
||||
assert projected_exceeded_date == real_datetime.date(2026, 4, 21)
|
||||
|
||||
|
||||
def test_handle_exception_on_proxy_preserves_429_status_code():
|
||||
"""Exceptions with status_code=429 should not be mapped to 500."""
|
||||
from litellm.proxy.utils import handle_exception_on_proxy
|
||||
|
||||
class FakeRateLimitError(Exception):
|
||||
def __init__(self):
|
||||
self.status_code = 429
|
||||
self.message = "Rate limit exceeded"
|
||||
self.param = None
|
||||
super().__init__(self.message)
|
||||
|
||||
result = handle_exception_on_proxy(FakeRateLimitError())
|
||||
assert result.code == "429"
|
||||
|
||||
|
||||
def test_handle_exception_on_proxy_defaults_to_500_without_status_code():
|
||||
"""Exceptions without status_code should map to 500."""
|
||||
from litellm.proxy.utils import handle_exception_on_proxy
|
||||
|
||||
result = handle_exception_on_proxy(Exception("unknown error"))
|
||||
assert result.code == "500"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue