Alexander Shorin committed 58e3e97

Remove 'Message not understood.' response if XMPP event couldn't be routed.

Primary idea was good, but it creates a lot of problems when error handler for
NotFound exception is not defined (most common case) and bot receives a lot of
unroutable events e.g. iq or presences.

Let bot creator create his own behavior for unknown messages or events instead
to decide default response behavior for him.

So default behavior for unroutable event is nothing. Check up debug logs to
see what you've missed.

Comments (0)

Files changed (2)


         rv = app(environ)
                           'welcome back, %s!' % environ['XMPP_JID'])
+    def test_presence_mismatch_doesnt_return_message_not_understood_resp(self):
+        app = xmppflask.XmppFlask(__name__)
+        @app.route_presence(from_jid='.*', type='available')
+        def presence():
+            return 'welcome back, %s!' % environ['XMPP_JID']
+        environ = {'XMPP_JID': 'foo@bar',
+                   'XMPP_EVENT': 'presence',
+                   'type': 'available'}
+        rv = app(environ)
+        self.assertEquals(u''.join(rv), '')
         if e in funcs: # maybe we have direct match
             handler = funcs[e]
-        for err, func in funcs.items(): # or
+        for err, func in funcs.items(): # or just handler by base exc class
             if isinstance(e, err):
                 handler = func
+        if isinstance(e, NotFound) and handler is not None:
+            return handler(e)
+        elif isinstance(e, NotFound):
+            return
+        self.logger.exception(e)
         if handler is None:
-            if isinstance(e, NotFound):
-                return u'Message not understood.'
-            else:
-                self.logger.exception(e)
-                if self.debug:
-                    raise e
+            if self.debug:
+                raise e
-            if not isinstance(e, NotFound):
-                self.logger.exception(e)
             return handler(e)
         return u'Some application error happened. Probably that\'s my bug :)'