Hello, I have setup a Django project that is being served via Nginx + gunicorn, however, I would like to handle graceful database failures. For example, if the ORM cannot query the database I would like to return a custom error message.
==> gunicorn.log <== [2017-06-07 06:06:01 +0000] [13] [DEBUG] GET /incidents/ [2017-06-07 06:06:11 +0000] [8] [CRITICAL] WORKER TIMEOUT (pid:13) [2017-06-07 06:06:11 +0000] [13] [INFO] Worker exiting (pid: 13) [2017-06-07 06:06:11 +0000] [20] [INFO] Booting worker with pid: 20 ==> nginx-error.log <== 2017/06/07 06:06:11 [error] 9#9: *1 upstream prematurely closed connection while reading response header from upstream, client: 172.17.0.1, s erver: XXXX, request: "GET /incidents/ HTTP/1.1", upstream: "http://unix:/webapp/run/gunicorn.sock:/incidents/", host: "192 .168.99.102:30061" I am using the following code snippet to test this, however, the json response is not sent back try: incidents = Incidents.objects.filter(user_and_team=request.user.client).exclude(status="Resolved") except OperationalError: return JsonResponse( {"error": trans("We encountered a problem")}, status=status.HTTP_503_SERVICE_UNAVAILABLE, ) Any ideas? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/719ff783-b448-4644-970e-34282185465a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.