diff --git a/account/custom_middleware.py b/account/custom_middleware.py index f658fd3..fb032dc 100644 --- a/account/custom_middleware.py +++ b/account/custom_middleware.py @@ -61,7 +61,8 @@ class CustomMiddleware(object): response = custom_response(custom_error) force_update = ForceUpdate.objects.filter(version=version, device_type=device_type).last() api_endpoint_checks = not any(endpoint in api_endpoint for endpoint in ['/admin/', '/api/v1/admin/']) - if not force_update and api_endpoint_checks: - custom_error = custom_error_response(ERROR_CODE['2079'], response_status=status.HTTP_404_NOT_FOUND) + if not force_update and version and device_type: + custom_error = custom_error_response(ERROR_CODE['2079'], + response_status=status.HTTP_308_PERMANENT_REDIRECT) response = custom_response(custom_error) return response diff --git a/account/utils.py b/account/utils.py index 57fc273..04c6791 100644 --- a/account/utils.py +++ b/account/utils.py @@ -204,8 +204,12 @@ def custom_error_response(detail, response_status): if not detail: """when details is empty""" detail = {} - return Response({"error": detail, "status": "failed", "code": response_status}, status=status.HTTP_400_BAD_REQUEST) - + if response_status == 406: + return Response({"error": detail, "status": "failed", "code": response_status,}, + status=status.HTTP_308_PERMANENT_REDIRECT) + else: + return Response({"error": detail, "status": "failed", "code": response_status}, + status=status.HTTP_400_BAD_REQUEST) def get_user_data(attrs): """ diff --git a/account/views.py b/account/views.py index 9d87c93..3b4c62c 100644 --- a/account/views.py +++ b/account/views.py @@ -696,6 +696,6 @@ class ForceUpdateViewSet(GenericViewSet, mixins.CreateModelMixin): obj_data = [ForceUpdate(**item) for item in request.data] try: ForceUpdate.objects.bulk_create(obj_data) - return custom_response(SUCCESS_CODE["3045"], response_status=status.HTTP_200_OK) + return custom_response(SUCCESS_CODE["3046"], response_status=status.HTTP_200_OK) except Exception as e: return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST) diff --git a/base/messages.py b/base/messages.py index ca9edb6..8930bdc 100644 --- a/base/messages.py +++ b/base/messages.py @@ -173,7 +173,8 @@ SUCCESS_CODE = { # remove guardian code request "3044": "Remove guardian code request successfully", # create faq - "3045": "Create FAQ data" + "3045": "Create FAQ data", + "3046": "Add App version successfully" } """status code error"""