mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Adds in call to new rate limit method in the redis client
- both V1 and V2 APIs - Rate limiting wrapped into a new method - check_rate_limiting - delegates to the previous daily limit and the new though put limit - Rate limiting done on key type. Each key has it's own limit (number of requests) and interval (time period of requests) - Configured in the config. Not done on a per-env basis though could be in the future.
This commit is contained in:
@@ -16,6 +16,19 @@ class TooManyRequestsError(InvalidRequest):
|
||||
self.message = self.message_template.format(sending_limit)
|
||||
|
||||
|
||||
class RateLimitError(InvalidRequest):
|
||||
status_code = 429
|
||||
message_template = 'Exceeded rate limit for key type {} of {} requests per {} seconds'
|
||||
|
||||
def __init__(self, sending_limit, interval, key_type):
|
||||
# normal keys are spoken of as "live" in the documentation
|
||||
# so using this in the error messaging
|
||||
if key_type == 'normal':
|
||||
key_type = 'live'
|
||||
|
||||
self.message = self.message_template.format(key_type.upper(), sending_limit, interval)
|
||||
|
||||
|
||||
class BadRequestError(InvalidRequest):
|
||||
status_code = 400
|
||||
message = "An error occurred"
|
||||
|
||||
Reference in New Issue
Block a user