Mercurial > p > roundup > code
changeset 7157:68ff3d2a9f6b
Handle KeyError if rate limit refills between update and status
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 23 Feb 2023 15:43:54 -0500 |
| parents | 6f09103a6522 |
| children | 89f84f0d7cd3 |
| files | roundup/rest.py |
| diffstat | 1 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/rest.py Thu Feb 23 15:34:44 2023 -0500 +++ b/roundup/rest.py Thu Feb 23 15:43:54 2023 -0500 @@ -2075,7 +2075,19 @@ # User exceeded limits: tell humans how long to wait # Headers above will do the right thing for api # aware clients. - msg = _("Api rate limits exceeded. Please wait: %s seconds.") % limitStatus['Retry-After'] + try: + retry_after = limitStatus['Retry-After'] + except KeyError: + # handle race condition. If the time between + # the call to grca.update and grca.status + # is sufficient to reload the bucket by 1 + # item, Retry-After will be missing from + # limitStatus. So report a 1 second delay back + # to the client. We treat update as sole + # source of truth for exceeded rate limits. + retry_after = 1 + + msg = _("Api rate limits exceeded. Please wait: %s seconds.") % retry_after output = self.error_obj(429, msg, source="ApiRateLimiter") else: for header, value in limitStatus.items():
