is_database_connection_error

This commit is contained in:
Ishaan Jaff 2025-03-26 14:55:40 -07:00
parent 4948673e35
commit f8caebc54b
3 changed files with 17 additions and 6 deletions

View file

@ -2070,6 +2070,10 @@ class ProxyErrorTypes(str, enum.Enum):
""" """
Object was over budget Object was over budget
""" """
no_db_connection = "no_db_connection"
"""
No database connection
"""
token_not_found_in_db = "token_not_found_in_db" token_not_found_in_db = "token_not_found_in_db"
""" """

View file

@ -144,6 +144,10 @@ class UserAPIKeyAuthExceptionHandler:
""" """
import prisma import prisma
return isinstance(e, DB_CONNECTION_ERROR_TYPES) or isinstance( if isinstance(e, DB_CONNECTION_ERROR_TYPES):
e, prisma.errors.PrismaError 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

View file

@ -675,7 +675,12 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
if ( if (
prisma_client is None prisma_client is None
): # if both master key + user key submitted, and user key != master key, and no db connected, raise an error ): # 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) ## check for cache hit (In-Memory Cache)
_user_role = None _user_role = None
@ -1001,8 +1006,6 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
route=route, route=route,
start_time=start_time, start_time=start_time,
) )
else:
raise Exception()
except Exception as e: except Exception as e:
return await UserAPIKeyAuthExceptionHandler._handle_authentication_error( return await UserAPIKeyAuthExceptionHandler._handle_authentication_error(
e=e, e=e,