Catch 401 errors

This commit is contained in:
Zeva Rose 2022-06-13 21:08:49 -06:00
parent 44bb91ad6d
commit f5a8312d78

View file

@ -9,6 +9,7 @@ from jarvis_core.db.models import TwitterAccount, TwitterFollow
from naff import Client
from naff.client.errors import NotFound
from naff.models.discord.embed import Embed
from tweepy import errors
from tweepy.asynchronous import AsyncStream
from tweepy.models import Status
@ -88,11 +89,21 @@ class JARVISTwitterStream(AsyncStream):
async def on_keep_alive(self) -> None:
"""Override keep-alive to track new accounts."""
await super().on_keep_alive()
ids = [x.twitter_id async for x in TwitterAccount.find()]
if ids != self.current_filter:
logger.debug("Follows have changed, disconnected")
try:
await super().on_keep_alive()
except errors.Unauthorized as e:
logger.error("Got 401, killing", stack_info=True)
logger.debug(f"{e.api_errors=}")
logger.debug(f"{e.api_messages=}")
self.disconnect()
except Exception:
logger.error("Encountered error with stream in keepalive", stack_info=True)
self.disconnect()
else:
ids = [x.twitter_id async for x in TwitterAccount.find()]
if ids != self.current_filter:
logger.debug("Follows have changed, disconnected")
self.disconnect()
async def on_status(self, status: Status) -> None:
"""