summaryrefslogtreecommitdiff
path: root/sleekxmpp/basexmpp.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-19 00:08:47 -0700
committerLance Stout <lancestout@gmail.com>2011-08-19 01:04:20 -0700
commitf92f96325ac12160554cdf94d98b6742671d67a1 (patch)
tree9b6057be903a1f96324f1c252f1141a6c130c8f8 /sleekxmpp/basexmpp.py
parentb98555c512ddb7452c9a217b1024b9e3163dea99 (diff)
downloadslixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.gz
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.bz2
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.xz
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.zip
Make Iq exceptions more discoverable and simpler to use.
IqError and IqTimeout now extend XMPPError, so if you don't care about the difference, you can use: try: self.do_something_with_iqs() except XMPPError: # Error? Timeout? I don't care! pass If you do need to distinguish between timeouts and error replies, you can still continue to use: try: self.do_somethin_with_iqs() except IqError as err: pass except IqTimeout: pass If you don't catch any Iq errors and you're processing a stanza then an error response will be sent, just like normal if you raise XMPPError or any other exception, except that the error messages will be generic to prevent leaking too much information.
Diffstat (limited to 'sleekxmpp/basexmpp.py')
-rw-r--r--sleekxmpp/basexmpp.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index 61aaeff8..02f775ac 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -13,9 +13,9 @@ import copy
import logging
import sleekxmpp
-from sleekxmpp import plugins
+from sleekxmpp import plugins, roster
+from sleekxmpp.exceptions import IqError, IqTimeout
-import sleekxmpp.roster as roster
from sleekxmpp.stanza import Message, Presence, Iq, Error, StreamError
from sleekxmpp.stanza.roster import Roster
from sleekxmpp.stanza.nick import Nick
@@ -743,6 +743,29 @@ class BaseXMPP(XMLStream):
self.event("changed_status", presence)
+ def exception(self, exception):
+ """
+ Process any uncaught exceptions, notably IqError and
+ IqTimeout exceptions.
+
+ Overrides XMLStream.exception.
+
+ Arguments:
+ exception -- An unhandled exception object.
+ """
+ if isinstance(exception, IqError):
+ iq = exception.iq
+ log.error('%s: %s' % (iq['error']['condition'],
+ iq['error']['text']))
+ log.warning('You should catch IqError exceptions')
+ elif isinstance(exception, IqTimeout):
+ iq = exception.iq
+ log.error('Request timed out: %s' % iq)
+ log.warning('You should catch IqTimeout exceptions')
+ else:
+ log.exception(exception)
+
+
# Restore the old, lowercased name for backwards compatibility.
basexmpp = BaseXMPP