Skip to content

Commit

Permalink
Better youtube error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaserlang committed Oct 29, 2024
1 parent 9310fd0 commit debe101
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tbot/twitch_bot/tasks/youtube_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,23 @@ async def check_youtube_chat(channel_id: str):

await asyncio.sleep(chat['pollingIntervalMillis'] / 1000)
except httpx.HTTPStatusError as e:
if e.response.status_code == 403:
if 'liveStreamingNotEnabled' in e.response.text:
logger.info(
f'Live streaming not enabled for {channel_id}, removing youtube chat task'
)
channel_tasks[channel_id].cancel()
del channel_tasks[channel_id]
bot.channels_check[channel_id]['youtube_live_chat_id'] = None
await cache_channel(channel_id)
if 'liveStreamingNotEnabled' in e.response.text:
logger.info(
f'Live streaming not enabled for {channel_id}, removing youtube chat task'
)
channel_tasks[channel_id].cancel()
del channel_tasks[channel_id]
bot.channels_check[channel_id]['youtube_live_chat_id'] = None
await cache_channel(channel_id)
elif 'liveChatEnded' in e.response.text:
bot.channels_check[channel_id]['youtube_live_chat_id'] = None
await cache_channel(channel_id)
await asyncio.sleep(60)
elif 'liveChatNotFound' in e.response.text:
await asyncio.sleep(60)
else:
logger.exception(e)
await asyncio.sleep(60)
except Exception as e:
logger.exception(e)
await asyncio.sleep(60)
Expand Down

0 comments on commit debe101

Please sign in to comment.