diff --git a/examples/echo_client.py b/examples/echo_client.py index 4a5a741..469acb2 100644 --- a/examples/echo_client.py +++ b/examples/echo_client.py @@ -145,14 +145,12 @@ class EchoBot(ClientXMPP): # decrypt_message returns Optional[str]. It is possible to get # body-less OMEMO message (see KeyTransportMessages), currently # used for example to send heartbeats to other devices. - if body is None: - return None - decoded = body.decode('utf8') - if self.is_command(decoded): - await self.handle_command(mto, mtype, decoded) - elif self.debug_level == LEVEL_DEBUG: - await self.encrypted_reply(mto, mtype, f'Echo: {decoded}') - return None + if body is not None: + decoded = body.decode('utf8') + if self.is_command(decoded): + await self.handle_command(mto, mtype, decoded) + elif self.debug_level == LEVEL_DEBUG: + await self.encrypted_reply(mto, mtype, f'Echo: {decoded}') except (MissingOwnKey,): # The message is missing our own key, it was not encrypted for # us, and we can't decrypt it. @@ -160,7 +158,6 @@ class EchoBot(ClientXMPP): mto, mtype, 'Error: Message not encrypted for me.', ) - return None except (NoAvailableSession,) as exn: # We received a message from that contained a session that we # don't know about (deleted session storage, etc.). We can't @@ -173,7 +170,6 @@ class EchoBot(ClientXMPP): 'Error: Message uses an encrypted ' 'session I don\'t know about.', ) - return None except (UndecidedException, UntrustedException) as exn: # We received a message from an untrusted device. We can # choose to decrypt the message nonetheless, with the @@ -189,13 +185,11 @@ class EchoBot(ClientXMPP): ) # We resend, setting the `allow_untrusted` parameter to True. await self.message_handler(msg, allow_untrusted=True) - return None except (EncryptionPrepareException,): # Slixmpp tried its best, but there were errors it couldn't # resolve. At this point you should have seen other exceptions # and given a chance to resolve them already. await self.plain_reply(mto, mtype, 'Error: I was not able to decrypt the message.') - return None except (Exception,) as exn: await self.plain_reply(mto, mtype, 'Error: Exception occured while attempting decryption.\n%r' % exn) raise