Add 5XX http code handling

This commit is contained in:
DevilXD
2022-05-15 14:43:22 +02:00
parent 0b32d09285
commit fcbda8fea2

View File

@@ -856,9 +856,15 @@ class Twitch:
for attempt in range(attempts):
logger.debug(f"Request: ({method=}, {url=}, {attempts=}, {kwargs=})")
try:
async with session.request(method, url, **kwargs) as response:
logger.debug(f"Response: {response.status}: {response}")
yield response
while True:
async with session.request(method, url, **kwargs) as response:
logger.debug(f"Response: {response.status}: {response}")
if response.status >= 500:
self.print("Twitter is down, retrying in 120 seconds...")
await asyncio.sleep(120)
continue
yield response
break
return
except aiohttp.ClientConnectionError as exc:
cause = exc