From 70fa18d155d6f6be7c54ba45bdfea5fdd5076893 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 9 May 2020 19:28:37 +0200 Subject: [PATCH] Fediverse: Better error on unknown profile. --- plugins/Fediverse/activitypub.py | 2 +- plugins/Fediverse/plugin.py | 4 ++-- plugins/Fediverse/test.py | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/Fediverse/activitypub.py b/plugins/Fediverse/activitypub.py index cc4b13aa4..97373d0fe 100644 --- a/plugins/Fediverse/activitypub.py +++ b/plugins/Fediverse/activitypub.py @@ -133,7 +133,7 @@ def webfinger(hostname, uri): template = _get_webfinger_url(hostname) assert template - with convert_exceptions(WebfingerError): + with convert_exceptions(ActorNotFound): content = web.getUrlContent( template.replace("{uri}", uri), headers={"Accept": "application/json"}, diff --git a/plugins/Fediverse/plugin.py b/plugins/Fediverse/plugin.py index abfa40173..a7cea3e23 100644 --- a/plugins/Fediverse/plugin.py +++ b/plugins/Fediverse/plugin.py @@ -145,9 +145,9 @@ class Fediverse(callbacks.Plugin): try: actor = ap.get_actor(localuser, hostname) - except ap.WebfingerError as e: + except ap.ActorNotFound as e: # Usually a 404 - irc.error(e.args[0], Raise=True) + irc.error("Unknown user %s." % username, Raise=True) irc.reply( _("\x02%s\x02 (@%s@%s): %s") diff --git a/plugins/Fediverse/test.py b/plugins/Fediverse/test.py index 31aa6e285..07990d822 100644 --- a/plugins/Fediverse/test.py +++ b/plugins/Fediverse/test.py @@ -86,5 +86,11 @@ class FediverseTestCase(PluginTestCase): # TODO: add a test with an instance which only allows fetches # with valid signatures. + def testProfileUnknown(self): + self.assertResponse( + "profile @nonexistinguser@oc.todon.fr", + "Error: Unknown user @nonexistinguser@oc.todon.fr.", + ) + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: