Catch 401 errors
This commit is contained in:
parent
44bb91ad6d
commit
f5a8312d78
1 changed files with 15 additions and 4 deletions
|
@ -9,6 +9,7 @@ from jarvis_core.db.models import TwitterAccount, TwitterFollow
|
||||||
from naff import Client
|
from naff import Client
|
||||||
from naff.client.errors import NotFound
|
from naff.client.errors import NotFound
|
||||||
from naff.models.discord.embed import Embed
|
from naff.models.discord.embed import Embed
|
||||||
|
from tweepy import errors
|
||||||
from tweepy.asynchronous import AsyncStream
|
from tweepy.asynchronous import AsyncStream
|
||||||
from tweepy.models import Status
|
from tweepy.models import Status
|
||||||
|
|
||||||
|
@ -88,11 +89,21 @@ class JARVISTwitterStream(AsyncStream):
|
||||||
|
|
||||||
async def on_keep_alive(self) -> None:
|
async def on_keep_alive(self) -> None:
|
||||||
"""Override keep-alive to track new accounts."""
|
"""Override keep-alive to track new accounts."""
|
||||||
await super().on_keep_alive()
|
try:
|
||||||
ids = [x.twitter_id async for x in TwitterAccount.find()]
|
await super().on_keep_alive()
|
||||||
if ids != self.current_filter:
|
except errors.Unauthorized as e:
|
||||||
logger.debug("Follows have changed, disconnected")
|
logger.error("Got 401, killing", stack_info=True)
|
||||||
|
logger.debug(f"{e.api_errors=}")
|
||||||
|
logger.debug(f"{e.api_messages=}")
|
||||||
self.disconnect()
|
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:
|
async def on_status(self, status: Status) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue