diff options
author | W. Trevor King <wking@tremily.us> | 2012-09-03 09:34:35 -0400 |
---|---|---|
committer | W. Trevor King <wking@tremily.us> | 2012-09-03 09:34:35 -0400 |
commit | 7c1db6f55380c3511ac305a6fe3c16315216b527 (patch) | |
tree | 679d7f2074c91ffc4753d464fecaf9a6b73897ff | |
parent | ec24b19779046c9bb2b39992b9847b34bc8ddba9 (diff) | |
download | bugseverywhere-7c1db6f55380c3511ac305a6fe3c16315216b527.tar.gz |
util:wsgi: add HandlerErrorApp to return HTTP errors.
-rw-r--r-- | libbe/util/wsgi.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libbe/util/wsgi.py b/libbe/util/wsgi.py index 0a3ebf9..0753295 100644 --- a/libbe/util/wsgi.py +++ b/libbe/util/wsgi.py @@ -267,6 +267,18 @@ class ExceptionApp (WSGI_Middleware): raise +class HandlerErrorApp (WSGI_Middleware): + """Catch HandlerErrors and return HTTP error pages. + """ + def _call(self, environ, start_response): + try: + return self.app(environ, start_response) + except HandlerError, e: + self.log_request(environ, status=str(e), bytes=0) + start_response('{} {}'.format(e.code, e.msg), e.headers) + return [] + + class BEExceptionApp (WSGI_Middleware): """Translate BE-specific exceptions """ @@ -620,6 +632,7 @@ class ServerCommand (libbe.command.base.Command): 'port':params['port'], } app = BEExceptionApp(app, logger=self.logger) + app = HandlerErrorApp(app, logger=self.logger) app = ExceptionApp(app, logger=self.logger) if params['ssl'] == True: details['protocol'] = 'HTTPS' |