Show more fediverse errors to the end user
This commit is contained in:
parent
76212faed4
commit
8ccbeb54d7
2 changed files with 28 additions and 13 deletions
|
@ -112,14 +112,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
|
|
||||||
def _get_from_outbox(self, username, instance):
|
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)
|
actor = ap_actor.Actor(actor_url)
|
||||||
if not actor.load():
|
if not actor.load():
|
||||||
raise utils.EventError("Failed to find user")
|
raise utils.EventError("Failed to load user")
|
||||||
|
|
||||||
items = actor.outbox.load()
|
items = actor.outbox.load()
|
||||||
nonreply = [actor.followers]
|
nonreply = [actor.followers]
|
||||||
|
|
|
@ -34,29 +34,43 @@ def activity_request(url, data=None, method="GET", type=ACTIVITY_TYPE,
|
||||||
HOSTMETA_TEMPLATE = "https://%s/.well-known/host-meta"
|
HOSTMETA_TEMPLATE = "https://%s/.well-known/host-meta"
|
||||||
WEBFINGER_TEMPLATE = "https://%s/.well-known/webfinger?resource={uri}"
|
WEBFINGER_TEMPLATE = "https://%s/.well-known/webfinger?resource={uri}"
|
||||||
|
|
||||||
|
class FindActorException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def find_actor(username, instance):
|
def find_actor(username, instance):
|
||||||
hostmeta = HOSTMETA_TEMPLATE % instance
|
hostmeta = HOSTMETA_TEMPLATE % instance
|
||||||
hostmeta_request = utils.http.Request(HOSTMETA_TEMPLATE % instance,
|
hostmeta_request = utils.http.Request(HOSTMETA_TEMPLATE % instance,
|
||||||
useragent=USERAGENT, parse=True, check_content_type=False)
|
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
|
webfinger_url = None
|
||||||
for item in hostmeta.data.find_all("link"):
|
if hostmeta.code == 200:
|
||||||
if item["rel"] and item["rel"][0] == "lrdd":
|
for item in hostmeta.data.find_all("link"):
|
||||||
webfinger_url = item["template"]
|
if item["rel"] and item["rel"][0] == "lrdd":
|
||||||
break
|
webfinger_url = item["template"]
|
||||||
|
break
|
||||||
|
|
||||||
if not webfinger_url:
|
if not webfinger_url:
|
||||||
webfinger_url = WEBFINGER_TEMPLATE % instance
|
webfinger_url = WEBFINGER_TEMPLATE % instance
|
||||||
webfinger_url = webfinger_url.replace("{uri}",
|
webfinger_url = webfinger_url.replace("{uri}",
|
||||||
"acct:%s@%s" % (username, instance), 1)
|
"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
|
actor_url = None
|
||||||
for link in webfinger.data["links"]:
|
if webfinger.code == 200:
|
||||||
if link["type"] == ACTIVITY_TYPE:
|
for link in webfinger.data["links"]:
|
||||||
return link["href"]
|
if link["type"] == ACTIVITY_TYPE:
|
||||||
|
return link["href"]
|
||||||
|
else:
|
||||||
|
raise FindActorException("Could not find user @%s@%s" %
|
||||||
|
(username, instance))
|
||||||
|
|
||||||
KNOWN_TAGS = ["p", "br"]
|
KNOWN_TAGS = ["p", "br"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue