fix(events): keep registration status reads nonblocking
This commit is contained in:
18
config/api_errors.py
Normal file
18
config/api_errors.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""HTTP handling for recoverable database errors."""
|
||||
|
||||
from django.http import JsonResponse
|
||||
|
||||
|
||||
def handle_database_operational_error(request, error):
|
||||
"""Return a retryable response when PostgreSQL rejects a lock wait."""
|
||||
cause = error.__cause__
|
||||
while cause is not None:
|
||||
if getattr(cause, "sqlstate", None) == "55P03" or getattr(cause, "pgcode", None) == "55P03":
|
||||
response = JsonResponse(
|
||||
{"detail": "درخواست بهدلیل شلوغی موقت پایگاه داده انجام نشد؛ کمی بعد دوباره تلاش کنید."},
|
||||
status=503,
|
||||
)
|
||||
response["Retry-After"] = "2"
|
||||
return response
|
||||
cause = cause.__cause__
|
||||
raise error
|
||||
Reference in New Issue
Block a user