fix(exception-mapping): scope connection-error check to status-less/500 responses

is_error_str_connection_error ran before the status_code dispatch with no
guard, so a genuine 401/429/etc response whose body text happened to
mention connection failures (e.g. "connection refused") would be
misclassified as APIConnectionError instead of its real error type.

Restrict the check to the status-less/500 wrapper case described in
#33969, matching the existing guard style used for invalid_request_error
in _map_azure_exception.

Addresses review comment from @Sanjays2402.
This commit is contained in:
Souravrajvi0 2026-07-21 03:20:11 +00:00 • committed by Sourav Rajvi
parent 51b5a6523d
commit 4ba3d16d68

View file

@ -408,7 +408,9 @@ def _map_openai_exception(
request=_request,
litellm_debug_info=extra_information,
)
elif ExceptionCheckers.is_error_str_connection_error(error_str):
elif ExceptionCheckers.is_error_str_connection_error(error_str) and getattr(
original_exception, "status_code", None
) in (None, 500):
raise APIConnectionError(
message=f"APIConnectionError: {exception_provider} - {message}",
llm_provider=custom_llm_provider,
@ -768,7 +770,9 @@ def _map_openai_like_exception(
llm_provider=custom_llm_provider,
model=model,
)
elif ExceptionCheckers.is_error_str_connection_error(error_str):
elif ExceptionCheckers.is_error_str_connection_error(error_str) and getattr(
original_exception, "status_code", None
) in (None, 500):
raise APIConnectionError(
message=f"{custom_llm_provider.capitalize()}Exception - {error_str}",
llm_provider=custom_llm_provider,
@ -1998,7 +2002,9 @@ def _map_azure_exception(
litellm_debug_info=extra_information,
response=getattr(original_exception, "response", None),
)
elif ExceptionCheckers.is_error_str_connection_error(error_str):
elif ExceptionCheckers.is_error_str_connection_error(error_str) and getattr(
original_exception, "status_code", None
) in (None, 500):
raise APIConnectionError(
message=f"{exception_provider} APIConnectionError - {message}",
llm_provider=custom_llm_provider,