Raise in HTTPClient.request when out of retries

Raise after loop completes without returning with most recent values
for r, data. This is a bit less fragile than checking tries < 4, since
changing the retry count requires changing values in multiple places.
(There seemed to already be handling in the 502 retry, tries <= 5,
which always evaluated to true, e.g.)
Previously, once out of retries, we would always return None without
raising.
This won't NameError so long as we make at least one HTTP request.
This commit is contained in:
khazhyk 2017-07-22 20:04:43 -07:00
parent 2850995062
commit 62cdfbdbcd

View File

@ -194,7 +194,7 @@ class HTTPClient:
continue continue
# we've received a 500 or 502, unconditional retry # we've received a 500 or 502, unconditional retry
if r.status in {500, 502} and tries <= 5: if r.status in {500, 502}:
yield from asyncio.sleep(1 + tries * 2, loop=self.loop) yield from asyncio.sleep(1 + tries * 2, loop=self.loop)
continue continue
@ -208,6 +208,8 @@ class HTTPClient:
finally: finally:
# clean-up just in case # clean-up just in case
yield from r.release() yield from r.release()
# We've run out of retries, raise.
raise HTTPException(r, data)
def get_attachment(self, url): def get_attachment(self, url):
resp = yield from self._session.get(url) resp = yield from self._session.get(url)