# HG changeset patch # User Tero Marttila # Date 1422565904 -7200 # Node ID 05707929ff6f013487c87c54dea37ed93299e56f # Parent 89bd5028b150f91ddf222c4f014082786036e436 qmsk.web.async: handle HTTPExceptions diff -r 89bd5028b150 -r 05707929ff6f 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)