Retry if send_message or edit_message encounter a 502.
This commit is contained in:
		| @@ -929,16 +929,23 @@ class Client: | |||||||
|         return channel |         return channel | ||||||
|  |  | ||||||
|     @asyncio.coroutine |     @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) |         resp = yield from self.session.request(method, url, data=data, headers=self.headers) | ||||||
|         tmp = request_logging_format.format(method=method, response=resp) |         tmp = request_logging_format.format(method=method, response=resp) | ||||||
|         log_fmt = 'In {}, {}'.format(name, tmp) |         log_fmt = 'In {}, {}'.format(name, tmp) | ||||||
|         log.debug(log_fmt) |         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: |         if resp.status == 429: | ||||||
|             retry = float(resp.headers['Retry-After']) / 1000.0 |             retry = float(resp.headers['Retry-After']) / 1000.0 | ||||||
|             yield from resp.release() |             yield from resp.release() | ||||||
|             yield from asyncio.sleep(retry) |             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 |         return resp | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user