diff options
author | 2021-03-09 08:50:07 +0200 | |
---|---|---|
committer | 2021-03-09 08:50:07 +0200 | |
commit | e096c708ee25a5a915462cf35a6d63d3ef68e26f (patch) | |
tree | b8b2d5b89840c3b85e15c69e02b43d1ef6540922 | |
parent | Merge branch 'main' into ks123/role-assigning (diff) |
Simplify role assigning rate limit handling
Co-authored-by: Hassan Abouelela <[email protected]>
-rw-r--r-- | backend/routes/forms/submit.py | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index 23444a0..4d15ab7 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -288,16 +288,10 @@ class SubmitForm(Route): async with httpx.AsyncClient() as client: resp = await client.put(url, headers=DISCORD_HEADERS) - if resp.status_code == 429: # We are rate limited - status = resp.status_code + # Handle Rate Limits + while resp.status_code == 429: retry_after = float(resp.headers["X-Ratelimit-Reset-After"]) - while status == 429: - await asyncio.sleep(retry_after) - r = await client.put(url, headers=DISCORD_HEADERS) - status = r.status_code - if status == 429: - retry_after = float(r.headers["X-Ratelimit-Reset-After"]) - else: - r.raise_for_status() - else: # For any other unexpected status, raise error. - resp.raise_for_status() + await asyncio.sleep(retry_after) + resp = await client.put(url, headers=DISCORD_HEADERS) + + resp.raise_for_status() |