I'm trying to make throttling on OTP authentication so user can only send one message every minute
class BurstRateThrottle(AnonRateThrottle, UserRateThrottle):
scope = 'burst'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES':
('rest_framework_simplejwt.authentication.JWTAuthentication',),
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
],
'DEFAULT_THROTTLE_RATES': {
'burst': '1/min',
'anon': '200/min',
'user': '250/min',
},
@api_view(['POST'])
@permission_classes([AllowAny])
@throttle_classes([BurstRateThrottle])
def login_send_token(request):
...
The problem with this is that the api gets throttled even when the phone number is wrong so I'm trying to only throttle when the OTP message is send or when the response is 200 or 201
Is there any way to access the response status code in allow_request method?
or to manually execute the throttle from the function that call twilio api?