xep-0231: fix TypeError when BoB cannot be found

Although it is not documented whether the get_bob API
call can return None, the default implementation can,
which raises a TypeError when the requested BoB is not
available. This commit prevents such TypeError by
raising a XMPPError instead.

References: https://todo.sr.ht/~nicoco/slidcord/23
This commit is contained in:
nicoco 2024-09-28 10:26:09 +02:00
parent db8ce9187c
commit b94c6716f7

View File

@ -10,6 +10,7 @@ from asyncio import Future
from typing import Optional
from slixmpp import JID
from slixmpp.exceptions import XMPPError
from slixmpp.stanza import Iq, Message, Presence
from slixmpp.xmlstream.handler import CoroutineCallback
from slixmpp.xmlstream.matcher import StanzaPath
@ -139,6 +140,13 @@ class XEP_0231(BasePlugin):
self.xmpp.event('bob', iq)
elif iq['type'] == 'get':
data = await self.api['get_bob'](iq['to'], None, iq['from'], args=cid)
if data is None:
raise XMPPError(
"item-not-found",
f"Bits of binary '{cid}' is not available",
)
if isinstance(data, Iq):
data['id'] = iq['id']
data.send()