This commit is contained in:
Hamza Imran 2026-11-06 05:03:44 +00:00 • committed by GitHub
commit a880dd99ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 0 deletions

View file

@ -1281,6 +1281,27 @@ def _map_vertex_exception(
) -> None:
status_code: Final[object] = getattr(original_exception, "status_code", None)
body_code: Final[int | None] = _get_body_error_code(error_str)
if (
exception_type == "TransportError"
or "TransportError" in type(original_exception).__name__
or "google.auth.exceptions.TransportError" in str(type(original_exception))
):
raise APIConnectionError(
message=f"{custom_llm_provider.capitalize()}Exception - Authentication TransportError: {error_str}",
llm_provider=custom_llm_provider,
model=model,
litellm_debug_info=extra_information,
)
if (
exception_type in ("RefreshError", "GoogleAuthError", "DefaultCredentialsError")
or "google.auth.exceptions" in str(type(original_exception))
):
raise AuthenticationError(
message=f"{custom_llm_provider.capitalize()}Exception - Authentication Error: {error_str}",
llm_provider=custom_llm_provider,
model=model,
litellm_debug_info=extra_information,
)
if "Vertex AI API has not been used in project" in error_str or "Unable to find your project" in error_str:
raise BadRequestError(
message=f"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}",

View file

@ -792,6 +792,37 @@ def test_vertex_wrapped_500_with_body_code_403_maps_to_bad_request() -> None:
assert excinfo.value.status_code == 403
def test_vertex_auth_transport_error_maps_to_api_connection_error() -> None:
import google.auth.exceptions
original_exception = google.auth.exceptions.TransportError("Socket timeout")
with pytest.raises(litellm.APIConnectionError) as excinfo:
exception_type(
model="gemini/gemini-2.5-flash",
original_exception=original_exception,
custom_llm_provider="vertex_ai",
)
assert isinstance(excinfo.value, litellm.APIConnectionError)
assert "Authentication TransportError" in str(excinfo.value)
assert "https://github.com/BerriAI/litellm/issues/new" not in str(excinfo.value)
def test_vertex_auth_refresh_error_maps_to_authentication_error() -> None:
import google.auth.exceptions
original_exception = google.auth.exceptions.RefreshError("Token has been expired or revoked")
with pytest.raises(litellm.AuthenticationError) as excinfo:
exception_type(
model="gemini/gemini-2.5-flash",
original_exception=original_exception,
custom_llm_provider="vertex_ai",
)
assert isinstance(excinfo.value, litellm.AuthenticationError)
assert excinfo.value.status_code == 401
class TestGetBodyErrorCode:
"""Unit tests for _get_body_error_code helper."""