diff options
| author | 2019-11-14 10:53:34 +0000 | |
|---|---|---|
| committer | 2019-11-14 10:53:34 +0000 | |
| commit | 8ccbeb54d7f1a2c238c6ecd6b24cd61ede3f3a19 (patch) | |
| tree | 48630e3c751daed7aea63ac6af29f25f21b4d1bc /modules | |
| parent | change formatted JOIN to have userhost in parens (diff) | |
| signature | ||
Show more fediverse errors to the end user
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/fediverse/__init__.py | 9 | ||||
| -rw-r--r-- | modules/fediverse/ap_utils.py | 32 |
2 files changed, 28 insertions, 13 deletions
diff --git a/modules/fediverse/__init__.py b/modules/fediverse/__init__.py index e002a2ef..362caf57 100644 --- a/modules/fediverse/__init__.py +++ b/modules/fediverse/__init__.py @@ -112,14 +112,15 @@ class Module(ModuleManager.BaseModule): def _get_from_outbox(self, username, instance): - actor_url = ap_utils.find_actor(username, instance) + try: + actor_url = ap_utils.find_actor(username, instance) + except ap_utils.FindActorException as e: + raise utils.EventError(str(e)) - if not actor_url: - raise utils.EventError("Failed to find user") actor = ap_actor.Actor(actor_url) if not actor.load(): - raise utils.EventError("Failed to find user") + raise utils.EventError("Failed to load user") items = actor.outbox.load() nonreply = [actor.followers] diff --git a/modules/fediverse/ap_utils.py b/modules/fediverse/ap_utils.py index e5ceacf5..bd0cacf4 100644 --- a/modules/fediverse/ap_utils.py +++ b/modules/fediverse/ap_utils.py @@ -34,29 +34,43 @@ def activity_request(url, data=None, method="GET", type=ACTIVITY_TYPE, HOSTMETA_TEMPLATE = "https://%s/.well-known/host-meta" WEBFINGER_TEMPLATE = "https://%s/.well-known/webfinger?resource={uri}" +class FindActorException(Exception): + pass + def find_actor(username, instance): hostmeta = HOSTMETA_TEMPLATE % instance hostmeta_request = utils.http.Request(HOSTMETA_TEMPLATE % instance, useragent=USERAGENT, parse=True, check_content_type=False) - hostmeta = utils.http.request(hostmeta_request) + try: + hostmeta = utils.http.request(hostmeta_request) + except: + raise FindActorException("Failed to get host-meta for %s" % instance) webfinger_url = None - for item in hostmeta.data.find_all("link"): - if item["rel"] and item["rel"][0] == "lrdd": - webfinger_url = item["template"] - break + if hostmeta.code == 200: + for item in hostmeta.data.find_all("link"): + if item["rel"] and item["rel"][0] == "lrdd": + webfinger_url = item["template"] + break if not webfinger_url: webfinger_url = WEBFINGER_TEMPLATE % instance webfinger_url = webfinger_url.replace("{uri}", "acct:%s@%s" % (username, instance), 1) - webfinger = activity_request(webfinger_url, type=JRD_TYPE) + try: + webfinger = activity_request(webfinger_url, type=JRD_TYPE) + except: + raise FindActorException("Failed to get webfinger for %s" % instance) actor_url = None - for link in webfinger.data["links"]: - if link["type"] == ACTIVITY_TYPE: - return link["href"] + if webfinger.code == 200: + for link in webfinger.data["links"]: + if link["type"] == ACTIVITY_TYPE: + return link["href"] + else: + raise FindActorException("Could not find user @%s@%s" % + (username, instance)) KNOWN_TAGS = ["p", "br"] |
