35
36
class FaultWrapper(base_wsgi.Middleware):
36
37
"""Calls down the middleware stack, making exceptions into faults."""
42
def status_to_type(status):
43
if not FaultWrapper._status_to_type:
44
for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError):
45
FaultWrapper._status_to_type[clazz.code] = clazz
46
return FaultWrapper._status_to_type.get(
47
status, webob.exc.HTTPInternalServerError)()
49
def _error(self, inner, req):
50
LOG.exception(_("Caught error: %s"), unicode(inner))
52
safe = getattr(inner, 'safe', False)
53
headers = getattr(inner, 'headers', None)
54
status = getattr(inner, 'code', 500)
58
msg_dict = dict(url=req.url, status=status)
59
LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict)
60
outer = self.status_to_type(status)
62
outer.headers = headers
63
# NOTE(johannes): We leave the explanation empty here on
64
# purpose. It could possibly have sensitive information
65
# that should not be returned back to the user. See
66
# bugs 868360 and 874472
67
# NOTE(eglynn): However, it would be over-conservative and
68
# inconsistent with the EC2 API to hide every exception,
69
# including those that are safe to expose, see bug 1021373
71
outer.explanation = '%s: %s' % (inner.__class__.__name__,
73
return wsgi.Fault(outer)
38
75
@webob.dec.wsgify(RequestClass=wsgi.Request)
39
76
def __call__(self, req):
41
78
return req.get_response(self.application)
42
79
except Exception as ex:
43
LOG.exception(_("Caught error: %s"), unicode(ex))
44
msg_dict = dict(url=req.url, status=500)
45
LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict)
46
exc = webob.exc.HTTPInternalServerError()
47
# NOTE(johannes): We leave the explanation empty here on
48
# purpose. It could possibly have sensitive information
49
# that should not be returned back to the user. See
50
# bugs 868360 and 874472
51
return wsgi.Fault(exc)
80
return self._error(ex, req)
54
83
class APIMapper(routes.Mapper):
55
84
def routematch(self, url=None, environ=None):
57
86
result = self._match("", environ)
58
87
return result[0], result[1]
59
88
return routes.Mapper.routematch(self, url, environ)
105
134
LOG.debug(_('Extended resource: %s'),
106
135
resource.collection)
108
wsgi_resource = wsgi.Resource(resource.controller)
138
if resource.inherits:
139
inherits = self.resources.get(resource.inherits)
140
if not resource.controller:
141
resource.controller = inherits.controller
142
wsgi_resource = wsgi.Resource(resource.controller,
109
144
self.resources[resource.collection] = wsgi_resource
111
146
controller=wsgi_resource,