bb-plane-fork/apps/api/plane/authentication/rate_limit.py
2025-07-04 15:32:21 +05:30

26 lines
818 B
Python

# Third party imports
from rest_framework.throttling import AnonRateThrottle
from rest_framework import status
from rest_framework.response import Response
# Module imports
from plane.authentication.adapter.error import (
AuthenticationException,
AUTHENTICATION_ERROR_CODES,
)
class AuthenticationThrottle(AnonRateThrottle):
rate = "30/minute"
scope = "authentication"
def throttle_failure_view(self, request, *args, **kwargs):
try:
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["RATE_LIMIT_EXCEEDED"],
error_message="RATE_LIMIT_EXCEEDED",
)
except AuthenticationException as e:
return Response(
e.get_error_dict(), status=status.HTTP_429_TOO_MANY_REQUESTS
)