mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
fix(proxy): default invalid streaming error codes to 500
This commit is contained in:
parent
230f653523
commit
f4872232e5
2 changed files with 10 additions and 2 deletions
|
|
@ -910,8 +910,8 @@ async def _parse_event_data_for_error(event_line: str | bytes) -> int | None:
|
|||
# Ensure error_code is a valid HTTP status code
|
||||
if error_code is not None and 100 <= error_code <= 599:
|
||||
return error_code
|
||||
elif error_code_raw is not None: # Log if original code was present but not valid
|
||||
verbose_proxy_logger.warning("Error has invalid or non-convertible code: %s", error_code_raw)
|
||||
verbose_proxy_logger.warning("Error has missing or invalid HTTP status code: %s", error_code_raw)
|
||||
return status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
except (orjson.JSONDecodeError, json.JSONDecodeError):
|
||||
# not a known error chunk
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -98,6 +98,14 @@ def test_attach_guardrail_information_copies_recorded_entries_onto_model_respons
|
|||
assert "guardrail_information" not in response.model_dump()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("error", [{"code": None}, {}, {"code": "not-a-status"}])
|
||||
async def test_parse_event_data_for_error_defaults_invalid_code_to_internal_error(error):
|
||||
event = f"data: {json.dumps({'error': error})}\n\n"
|
||||
|
||||
assert await _parse_event_data_for_error(event) == status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
def test_attach_guardrail_information_reports_empty_list_when_nothing_ran():
|
||||
response = litellm.ModelResponse()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue