Properly handle HTTP stream errors
This commit is contained in:
parent
f5a8312d78
commit
969999fc46
1 changed files with 14 additions and 15 deletions
|
@ -9,7 +9,6 @@ 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
|
||||||
|
|
||||||
|
@ -89,22 +88,22 @@ 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."""
|
||||||
try:
|
|
||||||
await super().on_keep_alive()
|
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()]
|
ids = [x.twitter_id async for x in TwitterAccount.find()]
|
||||||
if ids != self.current_filter:
|
if ids != self.current_filter:
|
||||||
logger.debug("Follows have changed, disconnected")
|
logger.debug("Follows have changed, disconnected")
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
|
async def on_request_error(self, status_code: int) -> None:
|
||||||
|
"""
|
||||||
|
Wrapper for on_request_error. Mainly used to catch 401 errors.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
status_code: HTTP Status Code
|
||||||
|
"""
|
||||||
|
logger.error(f"Received status code {status_code} while streaming, restarting")
|
||||||
|
self.disconnect()
|
||||||
|
|
||||||
async def on_status(self, status: Status) -> None:
|
async def on_status(self, status: Status) -> None:
|
||||||
"""
|
"""
|
||||||
Process new statuses.
|
Process new statuses.
|
||||||
|
|
Loading…
Add table
Reference in a new issue