Commit 988398bb authored by Philipp Hörist's avatar Philipp Hörist

Return consistent error results

parent ee45ce4a
Pipeline #3037 passed with stages
in 19 seconds
......@@ -24,6 +24,7 @@ from nbxmpp.structs import BlockingListResult
from nbxmpp.structs import CommonResult
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
log = logging.getLogger('nbxmpp.m.blocking')
......@@ -43,9 +44,7 @@ class Blocking:
def _blocking_list_received(self, stanza):
blocked = []
if not isResultNode(stanza):
log.info('Error: %s', stanza.getErrorMsg())
return BlockingListResult(blocking_list=blocked,
error=stanza.getErrorMsg())
return raise_error(log.info, stanza)
blocklist = stanza.getTag('blocklist', namespace=NS_BLOCKING)
for item in blocklist.getTags('item'):
......@@ -75,7 +74,5 @@ class Blocking:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
log.info('Error: %s', stanza.getErrorMsg())
return CommonResult(jid=stanza.getFrom(),
error=stanza.getErrorMsg())
return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
......@@ -31,6 +31,7 @@ from nbxmpp.util import to_xs_boolean
from nbxmpp.util import validate_jid
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
from nbxmpp.modules.pubsub import get_pubsub_item
from nbxmpp.modules.pubsub import get_pubsub_request
from nbxmpp.modules.pubsub import get_bookmark_publish_options
......@@ -123,8 +124,7 @@ class Bookmarks:
@callback
def _bookmarks_received(self, stanza, type_):
if not isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return []
return raise_error(log.info, stanza)
bookmarks = []
if type_ == BookmarkStoreType.PUBSUB:
......@@ -187,4 +187,4 @@ class Bookmarks:
@staticmethod
def _on_private_store_result(_con, stanza):
if not isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return raise_error(log.info, stanza)
......@@ -50,6 +50,7 @@ from nbxmpp.structs import MucDestroyed
from nbxmpp.util import validate_jid
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
from nbxmpp.modules.dataforms import extend_form
log = logging.getLogger('nbxmpp.m.muc')
......@@ -488,9 +489,7 @@ class MUC:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return CommonResult(jid=stanza.getFrom(),
error=stanza.getError())
return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
@staticmethod
......
......@@ -29,6 +29,7 @@ from nbxmpp.structs import PubSubEventData
from nbxmpp.structs import CommonResult
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
log = logging.getLogger('nbxmpp.m.pubsub')
......@@ -93,9 +94,7 @@ class PubSub:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return CommonResult(jid=stanza.getFrom(),
error=stanza.getError())
return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
......
......@@ -29,6 +29,7 @@ from nbxmpp.structs import AvatarMetaData
from nbxmpp.structs import AvatarData
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
from nbxmpp.util import raise_error
from nbxmpp.modules.pubsub import get_pubsub_request
log = logging.getLogger('nbxmpp.m.user_avatar')
......@@ -54,6 +55,11 @@ class UserAvatar:
item = properties.pubsub_event.item
metadata = item.getTag('metadata', namespace=NS_AVATAR_METADATA)
if metadata is None:
log.warning('No metadata node found')
log.warning(stanza)
raise NodeProcessed
if not metadata.getChildren():
pubsub_event = properties.pubsub_event._replace(empty=True)
log.info('Received avatar metadata: %s - no avatar set',
......@@ -83,8 +89,7 @@ class UserAvatar:
jid = JID(self._client.get_bound_jid().getBare())
if not isResultNode(stanza):
log.info('Error: %s', stanza.getError())
raise NodeProcessed
return raise_error(log.warning, stanza)
pubsub_node = stanza.getTag('pubsub')
items_node = pubsub_node.getTag('items')
......@@ -93,16 +98,18 @@ class UserAvatar:
sha = item.getAttr('id')
data_node = item.getTag('data', namespace=NS_AVATAR_DATA)
if data_node is None:
log.warning('No data node found')
log.warning(stanza)
raise NodeProcessed
return raise_error(log.warning, stanza, 'stanza-malformed',
'No data node found')
data = data_node.getData()
if data is None:
log.warning('Data node empty')
log.warning(stanza)
raise NodeProcessed
return raise_error(log.warning, stanza, 'stanza-malformed',
'Data node empty')
try:
data = base64.b64decode(data.encode('utf-8'))
except Exception as error:
return raise_error(log.warning, stanza, 'stanza-malformed', error)
data = base64.b64decode(data.encode('utf-8'))
log.info('Received avatar data: %s %s', jid, sha)
return AvatarData(jid, sha, data)
......@@ -202,6 +202,8 @@ def to_xs_boolean(value):
def raise_error(log_method, stanza, type_=None, message=None):
if message is not None:
message = str(message)
if type_ is None:
type_ = stanza.getError()
message = stanza.getErrorMsg()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment