From fcbda8fea26c68f684ff0dbbae0ee6503acc4539 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 15 May 2022 14:43:22 +0200 Subject: [PATCH] Add 5XX http code handling --- twitch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/twitch.py b/twitch.py index 9a33d00..5daf172 100644 --- a/twitch.py +++ b/twitch.py @@ -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