diff options
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/__init__.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index f49c721ff..c1ce7ee94 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -37,18 +37,21 @@ LOG = logging.getLogger(__name__) class FaultWrapper(base_wsgi.Middleware): """Calls down the middleware stack, making exceptions into faults.""" - def __init__(self, application): - self.status_to_type = {} - for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError): - self.status_to_type[clazz.code] = clazz - super(FaultWrapper, self).__init__(application) + _status_to_type = {} + + @staticmethod + def status_to_type(status): + if not FaultWrapper._status_to_type: + for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError): + FaultWrapper._status_to_type[clazz.code] = clazz + return FaultWrapper._status_to_type.get( + status, webob.exc.HTTPInternalServerError)() def _error(self, inner, req, headers=None, status=500, safe=False): LOG.exception(_("Caught error: %s"), unicode(inner)) msg_dict = dict(url=req.url, status=status) LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict) - outer = self.status_to_type.get(status, - webob.exc.HTTPInternalServerError)() + outer = self.status_to_type(status) if headers: outer.headers = headers # NOTE(johannes): We leave the explanation empty here on |
