mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(proxy): read a provider error's HTTP status before its error code
OpenAI-shaped provider errors carry their string error code (invalid_value) on .code, so reading .code first left a provider 400 with no status and logged it at ERROR
This commit is contained in:
parent
b5057898b4
commit
3c7bf1a3e7
2 changed files with 13 additions and 4 deletions
|
|
@ -312,12 +312,12 @@ def _raised_from(exception: BaseException) -> BaseException | None:
|
|||
|
||||
|
||||
def _http_status(exception: BaseException) -> int | None:
|
||||
code: Final[object] = getattr(exception, "code", None)
|
||||
status_code: Final[object] = code if code is not None else getattr(exception, "status_code", None)
|
||||
if status_code is None or isinstance(status_code, bool):
|
||||
status_code: Final[object] = getattr(exception, "status_code", None)
|
||||
status: Final[object] = status_code if status_code is not None else getattr(exception, "code", None)
|
||||
if status is None or isinstance(status, bool):
|
||||
return None
|
||||
try:
|
||||
return int(str(status_code))
|
||||
return int(str(status))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -617,6 +617,15 @@ class TestIsClientCausedFailure:
|
|||
),
|
||||
id="mapped_provider_400",
|
||||
),
|
||||
pytest.param(
|
||||
BadRequestError(
|
||||
message="Invalid size '13x13'",
|
||||
model="gpt-image-2",
|
||||
llm_provider="openai",
|
||||
body={"code": "invalid_value", "param": "size", "type": "invalid_request_error"},
|
||||
),
|
||||
id="mapped_provider_400_with_a_provider_error_code",
|
||||
),
|
||||
pytest.param(HTTPException(status_code=400), id="proxy_400"),
|
||||
pytest.param(HTTPException(status_code=403), id="proxy_403"),
|
||||
pytest.param(HTTPException(status_code=429), id="proxy_429"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue