Add: Exception on timeout

This commit is contained in:
dx-tan 2023-12-07 19:52:29 +07:00
parent a5dae88e77
commit 8223606e95
2 changed files with 7 additions and 2 deletions

View File

@ -19,7 +19,7 @@ from ..annotation.api import throw_on_failure
from ..constant.common import allowed_p_type, ProcessType, REQUEST_ID, FOLDER_TYPE, \ from ..constant.common import allowed_p_type, ProcessType, REQUEST_ID, FOLDER_TYPE, \
FolderFileType, TEMPLATE_ID, EntityStatus, standard_ocr_list, pdf_extensions, image_extensions, allowed_file_extensions FolderFileType, TEMPLATE_ID, EntityStatus, standard_ocr_list, pdf_extensions, image_extensions, allowed_file_extensions
from ..exception.exceptions import RequiredFieldException, InvalidException, NotFoundException, \ from ..exception.exceptions import RequiredFieldException, InvalidException, NotFoundException, \
PermissionDeniedException, LimitReachedException, LockedEntityException, FileContentInvalidException PermissionDeniedException, LimitReachedException, LockedEntityException, FileContentInvalidException, ServiceTimeoutException
from ..models import SubscriptionRequest, UserProfile, SubscriptionRequestFile, OcrTemplate, Subscription from ..models import SubscriptionRequest, UserProfile, SubscriptionRequestFile, OcrTemplate, Subscription
from ..response.ReportSerializer import ReportSerializer from ..response.ReportSerializer import ReportSerializer
from ..utils import FileUtils, ProcessUtil from ..utils import FileUtils, ProcessUtil
@ -284,7 +284,7 @@ class CtelViewSet(viewsets.ViewSet):
continue continue
return Response(status=status.HTTP_200_OK, data=serializer.data[0]) return Response(status=status.HTTP_200_OK, data=serializer.data[0])
return JsonResponse(status=status.HTTP_504_GATEWAY_TIMEOUT, data={"status": "timeout",f"request_id": "{rq_id}"}) raise ServiceTimeoutException(excArgs=f"{rq_id}")
@extend_schema(request=None, responses=None, tags=['data']) @extend_schema(request=None, responses=None, tags=['data'])

View File

@ -41,6 +41,11 @@ class ServiceUnavailableException(GeneralException):
default_code = 5030 default_code = 5030
default_detail = 'Service temporarily unavailable, try again later.' default_detail = 'Service temporarily unavailable, try again later.'
class ServiceTimeoutException(GeneralException):
status_code = 503
default_code = 5031
default_detail = 'Timeout waiting for the result, try again later.'
detail_with_arg = '{}'
class LockedEntityException(GeneralException): class LockedEntityException(GeneralException):
status_code = status.HTTP_423_LOCKED status_code = status.HTTP_423_LOCKED