]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make exception handling in AsyncHTTPClient more customizable 158/head
authorAlberto García Hierro <alberto@garciahierro.com>
Sat, 2 Oct 2010 16:57:35 +0000 (18:57 +0200)
committerAlberto García Hierro <alberto@garciahierro.com>
Tue, 26 Oct 2010 20:04:16 +0000 (22:04 +0200)
Call handle_callback_exception() with the callback as argument
instead of hardcoding the call to logging.debug(). This way, users
can add their own exception handling code by subclassing
AsyncHTTPClient.

Default implementation for handle_callback_exception() calls that
same function on the IOLoop associated to this AsyncHTTPClient
instance, so users can handle any exceptions raised from their
callbacks just by overriding handle_callback_exception() in IOLoop.

tornado/httpclient.py

index 26e447cc90348a959425bf81ca3aa98e4e0eb0f7..5857f19197436f692155e1d65f121e87a3b16e07 100644 (file)
@@ -350,8 +350,11 @@ class AsyncHTTPClient(object):
         except (KeyboardInterrupt, SystemExit):
             raise
         except:
-            logging.error("Exception in callback %r", info["callback"],
-                          exc_info=True)
+            self.handle_callback_exception(info["callback"])
+
+
+    def handle_callback_exception(self, callback):
+        self.io_loop.handle_callback_exception(callback)
 
 # For backwards compatibility: Tornado 1.0 included a new implementation of
 # AsyncHTTPClient that has since replaced the original.  Define an alias