mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix: ProxyException.__str__ returns message instead of empty string
Adds __str__ to ProxyException so str(exc) returns the message rather than an empty string. Fixes #22644
This commit is contained in:
parent
3a2cba43dc
commit
6a3a4beca8
2 changed files with 30 additions and 0 deletions
|
|
@ -3276,6 +3276,9 @@ class ProxyException(Exception):
|
|||
elif RouterErrors.no_deployments_with_tag_routing.value in self.message:
|
||||
self.code = "401"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Converts the ProxyException instance to a dictionary."""
|
||||
error_dict: Dict[str, Optional[Union[str, Dict]]] = {
|
||||
|
|
|
|||
27
tests/test_litellm/proxy/test_proxy_exception.py
Normal file
27
tests/test_litellm/proxy/test_proxy_exception.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""Tests for ProxyException.__str__.
|
||||
|
||||
Related issue: https://github.com/BerriAI/litellm/issues/22644
|
||||
"""
|
||||
|
||||
from litellm.proxy._types import ProxyException
|
||||
|
||||
|
||||
def test_proxy_exception_str_returns_message():
|
||||
exc = ProxyException(
|
||||
message="This is an error",
|
||||
type="invalid_request_error",
|
||||
param="model",
|
||||
code=400,
|
||||
)
|
||||
assert str(exc) == "This is an error"
|
||||
|
||||
|
||||
def test_proxy_exception_str_with_non_string_message():
|
||||
exc = ProxyException(
|
||||
message=42,
|
||||
type="server_error",
|
||||
param=None,
|
||||
code=500,
|
||||
)
|
||||
# __init__ already calls str(message)
|
||||
assert str(exc) == "42"
|
||||
Loading…
Add table
Reference in a new issue