conflict error
This commit is contained in:
parent
492d06b5ba
commit
0365d17095
4 changed files with 14 additions and 14 deletions
|
|
@ -75,6 +75,7 @@ class StatusView(APIView):
|
|||
|
||||
class HealthcheckView(APIView):
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get(self, request, format=None):
|
||||
data = {
|
||||
"is_healthy": True
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from oauth2_provider.models import get_access_token_model, get_application_model
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient, APITestCase
|
||||
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ class GooyalOAuth2Tests(APITestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
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.save()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from apps.gooyal_oauth2.models import AccessToken
|
||||
from utils.exceptions import Conflict
|
||||
|
||||
|
||||
def get_application(request):
|
||||
try:
|
||||
|
|
@ -31,18 +33,7 @@ class TokenLimitThrottle:
|
|||
if request.auth.token in active_tokens:
|
||||
return True
|
||||
else:
|
||||
False
|
||||
# raise ServiceUnavailable(code='max_allowed_session_reached')
|
||||
raise Conflict(code='max_allowed_session_reached')
|
||||
|
||||
else:
|
||||
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
|
||||
|
|
@ -82,7 +82,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
|
||||
|
||||
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_code = 'unprocessable_entity'
|
||||
|
||||
|
|
@ -91,3 +91,10 @@ class ServiceUnavailable(APIException):
|
|||
default_ = _('SERVICE_UNAVAILABLE')
|
||||
default_code = 'service_unavailable'
|
||||
default_detail = 'Service Unavailable'
|
||||
|
||||
|
||||
class Conflict(APIException):
|
||||
status_code = status.HTTP_409_CONFLICT
|
||||
default_ = _('CONFLICT')
|
||||
default_code = 'conflict'
|
||||
default_detail = 'Conflict'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue