From 6916f0f69123fc228e598ce23707788cfbdda312 Mon Sep 17 00:00:00 2001 From: Thibauld Nion Date: Sat, 15 Jun 2024 20:53:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Catch=20twitter=20error=20at=20a?= =?UTF-8?q?=20higer=20call=20site=20to=20protect=20the=20overall=20app.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wom_tributary/tasks.py | 25 ++++++++++++++----------- wom_tributary/utils/twitter_oauth.py | 6 ------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/wom_tributary/tasks.py b/wom_tributary/tasks.py index e752fed..4d16c29 100644 --- a/wom_tributary/tasks.py +++ b/wom_tributary/tasks.py @@ -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( diff --git a/wom_tributary/utils/twitter_oauth.py b/wom_tributary/utils/twitter_oauth.py index e28b2a7..55e542a 100644 --- a/wom_tributary/utils/twitter_oauth.py +++ b/wom_tributary/utils/twitter_oauth.py @@ -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 @@ -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