Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Jul 23, 2023
1 parent 895add3 commit 9cc096a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pajbot/managers/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import tweepy
from autobahn.twisted.websocket import WebSocketClientFactory, WebSocketClientProtocol
from tweepy.errors import NotFound
from tweepy.errors import NotFound, Unauthorized, Forbidden
from twisted.internet.protocol import ReconnectingClientFactory

if TYPE_CHECKING:
Expand Down Expand Up @@ -193,6 +193,16 @@ def get_last_tweet(self, username: str) -> str:
created_at = tweet.created_at.replace(tzinfo=datetime.timezone.utc)
tweet_message = stringify_tweet(tweet)
return f"{tweet_message} ({time_since(now().timestamp(), created_at.timestamp(), time_format='short')} ago)"
except Unauthorized:
log.error(
"Unable to get last tweet, got error 401 Unauthorized from Twitter. Validate that your Twitter credentials are correct"
)
return "Twitter error: Bad token"
except Forbidden as e:
log.error(
f"Unable to get last tweet, got error 401 Unauthorized from Twitter. Validate that your Twitter credentials are correct. {' '.join(e.api_messages)}"
)
return "Twitter error: Need to pay for access"
except Exception:
log.exception("Exception caught while getting last tweet")
return "FeelsBadMan"
Expand Down

0 comments on commit 9cc096a

Please sign in to comment.