From 4ba3d16d688cec7759e9c3afa7c47900ea69e8f5 Mon Sep 17 00:00:00 2001 From: Souravrajvi0 Date: Tue, 21 Jul 2026 03:20:11 +0000 Subject: [PATCH] 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. --- .../litellm_core_utils/exception_mapping_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index ce20be69e13..f6953c7b32a 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -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,