Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

is_database_connection_error

Ishaan Jafff8caebc54b28
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index c0fb0750ebd..104d1e7338b 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -2070,6 +2070,10 @@ class ProxyErrorTypes(str, enum.Enum):
"""
Object was over budget
"""
+ no_db_connection = "no_db_connection"
+ """
+ No database connection
+ """
token_not_found_in_db = "token_not_found_in_db"
"""
diff --git a/litellm/proxy/auth/auth_exception_handler.py b/litellm/proxy/auth/auth_exception_handler.py
index 5b314ef9315..c1a546b569f 100644
--- a/litellm/proxy/auth/auth_exception_handler.py
+++ b/litellm/proxy/auth/auth_exception_handler.py
@@ -144,6 +144,10 @@ class UserAPIKeyAuthExceptionHandler:
"""
import prisma
- return isinstance(e, DB_CONNECTION_ERROR_TYPES) or isinstance(
- e, prisma.errors.PrismaError
- )
+ if isinstance(e, DB_CONNECTION_ERROR_TYPES):
+ return True
+ if isinstance(e, prisma.errors.PrismaError):
+ return True
+ if isinstance(e, ProxyException) and e.type == ProxyErrorTypes.no_db_connection:
+ return True
+ return False
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py
index 06fa5608661..85ee76ff319 100644
--- a/litellm/proxy/auth/user_api_key_auth.py
+++ b/litellm/proxy/auth/user_api_key_auth.py
@@ -675,7 +675,12 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
if (
prisma_client is None
): # if both master key + user key submitted, and user key != master key, and no db connected, raise an error
- raise Exception("No connected db.")
+ raise ProxyException(
+ message="No connected db.",
+ type=ProxyErrorTypes.no_db_connection,
+ code=400,
+ param=None,
+ )
## check for cache hit (In-Memory Cache)
_user_role = None
@@ -1001,8 +1006,6 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
route=route,
start_time=start_time,
)
- else:
- raise Exception()
except Exception as e:
return await UserAPIKeyAuthExceptionHandler._handle_authentication_error(
e=e,