Merge "Add a global error handler for wsgi"

This commit is contained in:
Jenkins 2015-09-13 07:37:02 +00:00 committed by Gerrit Code Review
commit e061305356
2 changed files with 10 additions and 1 deletions

View File

@ -22,7 +22,7 @@ from zaqar.tests.unit.transport.wsgi import base
@ddt.ddt @ddt.ddt
class TestQueueLifecycleMongoDB(base.V1BaseFaulty): class TestQueueLifecycleMongoDB(base.V1Base):
config_file = 'wsgi_mongodb.conf' config_file = 'wsgi_mongodb.conf'

View File

@ -19,6 +19,7 @@ from wsgiref import simple_server
import falcon import falcon
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import six
from zaqar.common import decorators from zaqar.common import decorators
from zaqar.common.transport.wsgi import helpers from zaqar.common.transport.wsgi import helpers
@ -98,6 +99,7 @@ class Driver(transport.DriverBase):
]) ])
self.app = falcon.API(before=self.before_hooks) self.app = falcon.API(before=self.before_hooks)
self.app.add_error_handler(Exception, self._error_handler)
for version_path, endpoints in catalog: for version_path, endpoints in catalog:
for route, resource in endpoints: for route, resource in endpoints:
@ -115,6 +117,13 @@ class Driver(transport.DriverBase):
self.app = auth.SignedHeadersAuth(self.app, auth_app) self.app = auth.SignedHeadersAuth(self.app, auth_app)
def _error_handler(self, exc, request, response, params):
if isinstance(exc, falcon.HTTPError):
raise exc
LOG.exception(exc)
raise falcon.HTTPInternalServerError('Internal server error',
six.text_type(exc))
def listen(self): def listen(self):
"""Self-host using 'bind' and 'port' from the WSGI config group.""" """Self-host using 'bind' and 'port' from the WSGI config group."""