From 2c0905919ffbe63f34c2d0eb9b668b2eaf97752d Mon Sep 17 00:00:00 2001 From: DaZuiZui Date: Fri, 24 Jul 2026 16:11:28 +0800 Subject: [PATCH] fix(proxy): return 503 when database connections are exhausted --- litellm/proxy/db/exception_handler.py | 5 +++++ .../proxy/auth/test_auth_exception_handler.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/litellm/proxy/db/exception_handler.py b/litellm/proxy/db/exception_handler.py index e4c565e4464..59775d2dd73 100644 --- a/litellm/proxy/db/exception_handler.py +++ b/litellm/proxy/db/exception_handler.py @@ -195,6 +195,11 @@ class PrismaDBExceptionHandler: """ import asyncio + from prisma.errors import DataError + + if isinstance(e, DataError) and e.code == "P2037": + return True + if PrismaDBExceptionHandler.is_database_connection_error(e): return True if PrismaDBExceptionHandler.is_database_transport_error(e): diff --git a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py b/tests/test_litellm/proxy/auth/test_auth_exception_handler.py index 11e6f483e35..2ab0a842b80 100644 --- a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py +++ b/tests/test_litellm/proxy/auth/test_auth_exception_handler.py @@ -122,6 +122,15 @@ async def test_handle_authentication_error_data_layer_errors_do_not_fall_back( OSError("network is unreachable"), HTTPClientClosedError(), PrismaError("can't reach database server"), + DataError( + data={ + "user_facing_error": { + "error_code": "P2037", + "message": "Too many database connections opened: FATAL: sorry, too many clients already", + "meta": {"database_error": "FATAL: sorry, too many clients already"}, + } + } + ), RawQueryError( data={ "user_facing_error": {