qmsk.web.async: handle HTTPExceptions
authorTero Marttila <terom@paivola.fi>
Thu, 29 Jan 2015 23:11:44 +0200
changeset 107 05707929ff6f
parent 106 89bd5028b150
child 108 e77b7c324a32
qmsk.web.async: handle HTTPExceptions
qmsk/web/async.py
--- a/qmsk/web/async.py	Thu Jan 29 22:16:16 2015 +0200
+++ b/qmsk/web/async.py	Thu Jan 29 23:11:44 2015 +0200
@@ -1,6 +1,7 @@
 import asyncio
 import qmsk.web.application
 import werkzeug
+import werkzeug.exceptions
 
 class Handler (qmsk.web.application.Handler) :
     @asyncio.coroutine
@@ -26,15 +27,21 @@
     @asyncio.coroutine
     def __call__ (self, environ, start_response):
         request = werkzeug.Request(environ)
-
-        handler, params = self.lookup(request)
+        
+        handler = None
 
         try:
+            handler, params = self.lookup(request)
+
             handler.init()
 
             response = yield from handler.respond_async(**params)
+        
+        except werkzeug.exceptions.HTTPException as error :
+            response = error
 
         finally:
-            handler.cleanup()
+            if handler:
+                handler.cleanup()
 
         return response(environ, start_response)