From 803bba71a6da58b51caacd3210db279c13faba9f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 22 Jan 2023 15:59:19 +1100 Subject: [PATCH] fix error handling - when using raise_for_status we need to catch an HTTPError, not a ConnectionError - simplify instance actor - use internal email address since it will never be used anyway, and make default username less likely to already be in use. --- bookwyrm/activitypub/base_activity.py | 11 +++++++---- bookwyrm/settings.py | 4 +--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 7befc5bc6..3adddfeb9 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -11,7 +11,7 @@ from django.utils.http import http_date from bookwyrm import models from bookwyrm.connectors import ConnectorException, get_data from bookwyrm.signatures import make_signature -from bookwyrm.settings import DOMAIN, INSTANCE_ACTOR_USERNAME, INSTANCE_ACTOR_EMAIL +from bookwyrm.settings import DOMAIN, INSTANCE_ACTOR_USERNAME from bookwyrm.tasks import app, MEDIUM logger = logging.getLogger(__name__) @@ -280,7 +280,10 @@ def resolve_remote_id( # load the data and create the object try: data = get_data(remote_id) - except ConnectorException as e: + except ConnectionError: + logger.info("Could not connect to host for remote_id: %s", remote_id) + return None + except requests.HTTPError as e: if (e.response is not None) and e.response.status_code == 401: # This most likely means it's a mastodon with secure fetch enabled. data = get_activitypub_data(remote_id) @@ -309,12 +312,12 @@ def get_representative(): """Get or create an actor representing the instance to sign requests to 'secure mastodon' servers""" username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}" + email = "bookwyrm@localhost" try: user = models.User.objects.get(username=username) except models.User.DoesNotExist: - email = INSTANCE_ACTOR_EMAIL user = models.User.objects.create_user( - username=username, email=email, local=True, localname=DOMAIN + username=username, email=email, local=True, localname=INSTANCE_ACTOR_USERNAME ) return user diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 528bf68e2..ed1447b05 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -372,6 +372,4 @@ if HTTP_X_FORWARDED_PROTO: SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # AUTHORIZED_FETCH Instance Actor -# WARNING this must both be unique - not used by any other user -INSTANCE_ACTOR_USERNAME = DOMAIN -INSTANCE_ACTOR_EMAIL = f"representative@{DOMAIN}" +INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor"