hi
is there any way that I throttle a request base on specific status code?
as you see in code, i throttle all request no matter what is the status code.
but i want to the throttle incoming request if all the latest request ends with 404 status code not any other status code
class CheckUserPhone(APIView):
throttle_scope = "check_phone"
throttle_classes = (ScopedRateThrottle,)
serializer_class = CheckUserPhoneSerializer
def post(self, request):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
phone = get_phone_from_serializer(serializer)
user = User.objects.filter(phone=phone)
if user.exist():
return Response({"message": LoginSituation.LOGIN_REQUIRED}, status=status.HTTP_200_OK)
sms_provider_result, code = generate_otp_and_send(phone)
if sms_provider_result:
save_otp_inside_cache(phone, code)
return Response(
{"message": LoginSituation.REGISTER_REQUIRED}, status=status.HTTP_404_NOT_FOUND
)
return Response({"message": FaultCode.SMS_PROVIDER_FAILURE}, status=status.HTTP_400_BAD_REQUEST)