diff --git a/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py b/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py index 58612a72..02e80a13 100644 --- a/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py +++ b/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py @@ -125,6 +125,10 @@ RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}") RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$") +class MissingLocalPartError(Exception): + """JID local part is missing""" + + class APGateway: IMPORT_NAME = IMPORT_NAME # show data send or received through HTTP, used for debugging @@ -668,7 +672,7 @@ class APGateway: user = self.period_encode(user) if not user: - raise exceptions.InternalError("there should be a user part") + raise MissingLocalPartError("there should be a local part") if node: account_elts.extend((node, "---")) @@ -2094,9 +2098,25 @@ class APGateway: raise exceptions.InternalError( "node or service is missing in mb_data" ) - target_ap_account = await self.get_ap_account_from_jid_and_node( - service, node - ) + try: + target_ap_account = await self.get_ap_account_from_jid_and_node( + service, node + ) + except MissingLocalPartError: + # we have no local part, this is probably a comment + try: + service = jid.JID(mb_data["author_jid"]) + if not mb_data["author_jid_verified"]: + raise KeyError + except KeyError: + raise exceptions.DataError( + "Can't identify post author. Be sure to use a pubsub service " + "setting the 'publisher' attribute." + ) + else: + target_ap_account = await self.get_ap_account_from_jid_and_node( + service, node + ) if self.is_virtual_jid(service): # service is a proxy JID for AP account actor_data = await self.get_ap_actor_data_from_account(target_ap_account)