From e8452011f76c3c026e016669b7c717285c7281b0 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Fri, 20 Jan 2023 19:55:38 +1100 Subject: [PATCH] handle get_data exceptions better Makes exception handling more precise, only raising status for 401s. Also fixes a string pylint was complaining about. --- bookwyrm/activitypub/base_activity.py | 3 ++- bookwyrm/connectors/abstract_connector.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 6fc600b77..a4affa172 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -306,7 +306,8 @@ def resolve_remote_id( def get_representative(): - """Get or create an actor representing the entire instance to sign requests to 'secure mastodon' servers""" + """Get or create an actor representing the instance + to sign requests to 'secure mastodon' servers""" username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}" try: user = models.User.objects.get(username=username) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index dbfb2668d..6dd8a3081 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -244,7 +244,11 @@ def get_data(url, params=None, timeout=settings.QUERY_TIMEOUT): raise ConnectorException(err) if not resp.ok: - resp.raise_for_status() + if resp.status_code == 401: + # this is probably an AUTHORIZED_FETCH issue + resp.raise_for_status() + else: + raise ConnectorException() try: data = resp.json() except ValueError as err: