comparison roundup/rest.py @ 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
comparison
equal deleted inserted replaced
7156:6f09103a6522 7157:68ff3d2a9f6b
2073 for header, value in limitStatus.items(): 2073 for header, value in limitStatus.items():
2074 self.client.setHeader(header, value) 2074 self.client.setHeader(header, value)
2075 # User exceeded limits: tell humans how long to wait 2075 # User exceeded limits: tell humans how long to wait
2076 # Headers above will do the right thing for api 2076 # Headers above will do the right thing for api
2077 # aware clients. 2077 # aware clients.
2078 msg = _("Api rate limits exceeded. Please wait: %s seconds.") % limitStatus['Retry-After'] 2078 try:
2079 retry_after = limitStatus['Retry-After']
2080 except KeyError:
2081 # handle race condition. If the time between
2082 # the call to grca.update and grca.status
2083 # is sufficient to reload the bucket by 1
2084 # item, Retry-After will be missing from
2085 # limitStatus. So report a 1 second delay back
2086 # to the client. We treat update as sole
2087 # source of truth for exceeded rate limits.
2088 retry_after = 1
2089
2090 msg = _("Api rate limits exceeded. Please wait: %s seconds.") % retry_after
2079 output = self.error_obj(429, msg, source="ApiRateLimiter") 2091 output = self.error_obj(429, msg, source="ApiRateLimiter")
2080 else: 2092 else:
2081 for header, value in limitStatus.items(): 2093 for header, value in limitStatus.items():
2082 # Retry-After will be 0 because 2094 # Retry-After will be 0 because
2083 # user still has quota available. 2095 # user still has quota available.

Roundup Issue Tracker: http://roundup-tracker.org/