Wednesday, June 7, 2017

Re: Django graceful database errors

On Wednesday 07 June 2017 00:15:29 Damian Myerscough wrote:

 

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

 

 

> try:

> incidents =

> Incidents.objects.filter(user_and_team=request.user.client).exclude(st

> atus="Resolved") except OperationalError:

> return JsonResponse(

> {"error": trans("We encountered a problem")},

> status=status.HTTP_503_SERVICE_UNAVAILABLE,

> )

>

> Any ideas?

 

Because your timeout hits before your code gets to except.

--

Melvyn Sopacua

No comments:

Post a Comment