aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-04-14 13:16:27 -0400
committerRapptz <[email protected]>2016-04-14 13:16:27 -0400
commit7adf761a35adeb6339f7a800be3119484927b12f (patch)
treeede6feef8b481056a75c14ea6ece251af368e9a6
parent[commands] CommandError derived exceptions in checks don't crash help. (diff)
downloaddiscord.py-7adf761a35adeb6339f7a800be3119484927b12f.tar.xz
discord.py-7adf761a35adeb6339f7a800be3119484927b12f.zip
Retry if send_message or edit_message encounter a 502.
-rw-r--r--discord/client.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py
index fa85f305..e8987baa 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -929,16 +929,23 @@ class Client:
return channel
@asyncio.coroutine
- def _rate_limit_helper(self, name, method, url, data):
+ def _rate_limit_helper(self, name, method, url, data, retries=0):
resp = yield from self.session.request(method, url, data=data, headers=self.headers)
tmp = request_logging_format.format(method=method, response=resp)
log_fmt = 'In {}, {}'.format(name, tmp)
log.debug(log_fmt)
+
+ if resp.status == 502 and retries < 5:
+ # retry the 502 request unconditionally
+ log.info('Retrying the 502 request to ' + name)
+ yield from asyncio.sleep(retries + 1)
+ return (yield from self._rate_limit_helper(name, method, url, data, retries + 1))
+
if resp.status == 429:
retry = float(resp.headers['Retry-After']) / 1000.0
yield from resp.release()
yield from asyncio.sleep(retry)
- return (yield from self._rate_limit_helper(name, method, url, data))
+ return (yield from self._rate_limit_helper(name, method, url, data, retries))
return resp