component AP gateway: fix wrong exception + use of mb_data["xml"] when it may be absent

This commit is contained in:
Goffi 2022-07-14 12:55:30 +02:00
commit e73d4ebeff

View file

@ -1404,7 +1404,7 @@ class APGateway:
Can be either an activity of an object Can be either an activity of an object
@return: AP Item's Object and microblog data @return: AP Item's Object and microblog data
@raise exceptions.DataError: something is invalid in the AP item @raise exceptions.DataError: something is invalid in the AP item
@raise NotImplemented: some AP data is not handled yet @raise NotImplementedError: some AP data is not handled yet
@raise error.StanzaError: error while contacting the AP server @raise error.StanzaError: error while contacting the AP server
""" """
is_activity = self.isActivity(ap_item) is_activity = self.isActivity(ap_item)
@ -1751,14 +1751,14 @@ class APGateway:
if client != self.client: if client != self.client:
return mess_data return mess_data
if mess_data["type"] not in ("chat", "normal"): if mess_data["type"] not in ("chat", "normal"):
log.warning(f"ignoring message with unexpected type: {mess_data['xml'].toXml()}") log.warning(f"ignoring message with unexpected type: {mess_data}")
return mess_data return mess_data
if not self.isLocal(mess_data["from"]): if not self.isLocal(mess_data["from"]):
log.warning(f"ignoring non local message: {mess_data['xml'].toXml()}") log.warning(f"ignoring non local message: {mess_data}")
return mess_data return mess_data
if not mess_data["to"].user: if not mess_data["to"].user:
log.warning( log.warning(
f"ignoring message addressed to gateway itself: {mess_data['xml'].toXml()}" f"ignoring message addressed to gateway itself: {mess_data}"
) )
return mess_data return mess_data
@ -1967,7 +1967,7 @@ class APGateway:
# we don't have a comment node set for this item # we don't have a comment node set for this item
from sat.tools.xml_tools import ppElt from sat.tools.xml_tools import ppElt
log.info(f"{ppElt(parent_item_elt.toXml())}") log.info(f"{ppElt(parent_item_elt.toXml())}")
raise NotImplemented() raise NotImplementedError()
else: else:
__, item_elt = await self.apItem2MbDataAndElt(ap_item) __, item_elt = await self.apItem2MbDataAndElt(ap_item)
await self._p.publish(client, comment_service, comment_node, [item_elt]) await self._p.publish(client, comment_service, comment_node, [item_elt])