fix(proxy): return 503 when database connections are exhausted

This commit is contained in:
DaZuiZui 2026-07-24 16:11:28 +08:00
parent bd753aecf3
commit 2c0905919f
2 changed files with 14 additions and 0 deletions

View file

@ -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):

View file

@ -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": {