From 4bec180c5119c4fbc1448397b47739d4a2a8e82b Mon Sep 17 00:00:00 2001 From: Ajay Singh Date: Fri, 25 Oct 2024 14:38:41 -0700 Subject: [PATCH 1/2] test this on stage --- graphql_api/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/graphql_api/views.py b/graphql_api/views.py index bb2afd631d..d15f5830a9 100644 --- a/graphql_api/views.py +++ b/graphql_api/views.py @@ -3,7 +3,7 @@ import os import socket import time -from asyncio import iscoroutine +from asyncio import iscoroutine, wait_for from typing import Any, Collection, Optional import regex @@ -239,7 +239,12 @@ async def post(self, request, *args, **kwargs): ) with RequestFinalizer(request): - response = await super().post(request, *args, **kwargs) + try: + response = await wait_for( + super().post(request, *args, **kwargs), timeout=3 + ) + except TimeoutError: + return JsonResponse({"error": "Request timed out"}, status=408) content = response.content.decode("utf-8") data = json.loads(content) From d6186222688dc0221c7612ef8a00578c46662f16 Mon Sep 17 00:00:00 2001 From: Ajay Singh Date: Mon, 28 Oct 2024 09:19:27 -0700 Subject: [PATCH 2/2] add timeout error to formatter --- graphql_api/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/graphql_api/views.py b/graphql_api/views.py index d15f5830a9..b5b16a8ed3 100644 --- a/graphql_api/views.py +++ b/graphql_api/views.py @@ -292,9 +292,7 @@ def error_formatter(self, error, debug=False): formatted["type"] = "ServerError" # if this is one of our own command exception, we can tell a bit more original_error = error.original_error - if isinstance(original_error, BaseException) or isinstance( - original_error, ServiceException - ): + if isinstance(original_error, (BaseException, ServiceException, TimeoutError)): formatted["message"] = original_error.message formatted["type"] = type(original_error).__name__ else: