conflict error

This commit is contained in:
Sayyid Hamid Mahdavi 2026-04-08 11:23:11 +03:30
parent 492d06b5ba
commit 0365d17095
4 changed files with 14 additions and 14 deletions

View file

@ -75,6 +75,7 @@ class StatusView(APIView):
class HealthcheckView(APIView): class HealthcheckView(APIView):
permission_classes = [AllowAny] permission_classes = [AllowAny]
def get(self, request, format=None): def get(self, request, format=None):
data = { data = {
"is_healthy": True "is_healthy": True

View file

@ -9,6 +9,7 @@ from django.test import TestCase
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from oauth2_provider.models import get_access_token_model, get_application_model from oauth2_provider.models import get_access_token_model, get_application_model
from rest_framework import status
from rest_framework.test import APIClient, APITestCase from rest_framework.test import APIClient, APITestCase
@ -120,7 +121,7 @@ class GooyalOAuth2Tests(APITestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
response = self.client.get(reverse("core:status"), HTTP_AUTHORIZATION=auth_2) response = self.client.get(reverse("core:status"), HTTP_AUTHORIZATION=auth_2)
self.assertEqual(response.status_code, 503) self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
self.application.max_allowed_session = 0 self.application.max_allowed_session = 0
self.application.save() self.application.save()

View file

@ -1,6 +1,8 @@
from rest_framework.throttling import UserRateThrottle from rest_framework.throttling import UserRateThrottle
from apps.gooyal_oauth2.models import AccessToken from apps.gooyal_oauth2.models import AccessToken
from utils.exceptions import Conflict
def get_application(request): def get_application(request):
try: try:
@ -31,18 +33,7 @@ class TokenLimitThrottle:
if request.auth.token in active_tokens: if request.auth.token in active_tokens:
return True return True
else: else:
False raise Conflict(code='max_allowed_session_reached')
# raise ServiceUnavailable(code='max_allowed_session_reached')
else: else:
return True return True
def wait(self):
"""
Optionally, return a recommended number of seconds to wait before
the next request.
"""
return None
from rest_framework.exceptions import Throttled

View file

@ -82,7 +82,7 @@ from django.utils.translation import gettext_lazy as _
class UnprocessableEntity(APIException): class UnprocessableEntity(APIException):
status_code = 422 status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
default_detail = 'The request was well-formed but cannot be processed due to semantic errors.' default_detail = 'The request was well-formed but cannot be processed due to semantic errors.'
default_code = 'unprocessable_entity' default_code = 'unprocessable_entity'
@ -91,3 +91,10 @@ class ServiceUnavailable(APIException):
default_ = _('SERVICE_UNAVAILABLE') default_ = _('SERVICE_UNAVAILABLE')
default_code = 'service_unavailable' default_code = 'service_unavailable'
default_detail = 'Service Unavailable' default_detail = 'Service Unavailable'
class Conflict(APIException):
status_code = status.HTTP_409_CONFLICT
default_ = _('CONFLICT')
default_code = 'conflict'
default_detail = 'Conflict'