exceptions: Make RateLimited into a subclass of JsonableError.

This simplifies the code, as it allows using the mechanism of converting
JsonableErrors into a response instead of having separate, but
ultimately similar, logic in RateLimitMiddleware.
We don't touch tests here because "rate limited" error responses are
already verified in test_external.py.
This commit is contained in:
Mateusz Mandera
2020-11-27 16:33:01 +01:00
committed by Alex Vandiver
parent 92ce2d0e31
commit 43a0c60e96
6 changed files with 45 additions and 25 deletions

View File

@@ -349,7 +349,8 @@ class OurAuthenticationForm(AuthenticationForm):
self.user_cache = authenticate(request=self.request, username=username, password=password,
realm=realm, return_data=return_data)
except RateLimited as e:
secs_to_freedom = int(float(str(e)))
assert e.secs_to_freedom is not None
secs_to_freedom = int(e.secs_to_freedom)
raise ValidationError(AUTHENTICATION_RATE_LIMITED_ERROR.format(secs_to_freedom))
if return_data.get("inactive_realm"):