Skip to content

Commit

Permalink
🐛 Catch twitter error at a higer call site to protect the overall app.
Browse files Browse the repository at this point in the history
  • Loading branch information
tibonihoo committed Jun 15, 2024
1 parent 5cc4fea commit 6916f0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
25 changes: 14 additions & 11 deletions wom_tributary/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ def __init__(self, is_auth, client, auth_url):


def get_twitter_auth_status(user_info, request = None):
force_single_user_token_if_any(user_info)
request_params, session = \
(request.GET, request.session) if request \
else ({},{})
client = twitter_oauth.try_get_authorized_client(
request_params, session, user_info)
is_auth = client is not None
auth_url = None if is_auth \
else twitter_oauth.generate_authorization_url(
session, user_info)
return AuthStatus(is_auth, client, auth_url)
try:
force_single_user_token_if_any(user_info)
request_params, session = \
(request.GET, request.session) if request \
else ({},{})
client = twitter_oauth.try_get_authorized_client(
request_params, session, user_info)
is_auth = client is not None
auth_url = None if is_auth \
else twitter_oauth.generate_authorization_url(
session, user_info)
return AuthStatus(is_auth, client, auth_url)
except Exception as e:
logging.error(f"Failed to get a proper Twitter AuthStatus because of '{e}'")


def create_reference_from_timeline_summary(
Expand Down
6 changes: 0 additions & 6 deletions wom_tributary/utils/twitter_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

import urllib.request, urllib.parse, urllib.error

import logging
logger = logging.getLogger(__name__)


import tweepy
from granary.twitter import Twitter
from oauth_dropins import twitter_auth
Expand Down Expand Up @@ -59,8 +55,6 @@ def try_get_authorized_client(
except urllib.error.HTTPError as e:
if e.code!=401: # HTTP Error 401: Authorization Required
raise
except Exception as e:
logging.error(f"Failed to set-up the Twitter client due to '{e}'")
return None


Expand Down

0 comments on commit 6916f0f

Please sign in to comment.