Merge "Fix TypeError conversion in API layer"
This commit is contained in:
commit
3fc3dbe6ab
|
@ -628,7 +628,11 @@ class ResourceExceptionHandler(object):
|
|||
elif isinstance(ex_value, exception.Invalid):
|
||||
raise Fault(exception.ConvertedException(
|
||||
code=ex_value.code, explanation=unicode(ex_value)))
|
||||
elif isinstance(ex_value, TypeError):
|
||||
|
||||
# Under python 2.6, TypeError's exception value is actually a string,
|
||||
# so test # here via ex_type instead:
|
||||
# http://bugs.python.org/issue7853
|
||||
elif issubclass(ex_type, TypeError):
|
||||
exc_info = (ex_type, ex_value, ex_traceback)
|
||||
LOG.error(_('Exception handling resource: %s') % ex_value,
|
||||
exc_info=exc_info)
|
||||
|
|
|
@ -752,6 +752,18 @@ class ResourceTest(test.TestCase):
|
|||
self.assertEqual(called, [2])
|
||||
self.assertEqual(response, 'foo')
|
||||
|
||||
def test_resource_exception_handler_type_error(self):
|
||||
"""A TypeError should be translated to a Fault/HTTP 400"""
|
||||
def foo(a,):
|
||||
return a
|
||||
|
||||
try:
|
||||
with wsgi.ResourceExceptionHandler():
|
||||
foo() # generate a TypeError
|
||||
self.fail("Should have raised a Fault (HTTP 400)")
|
||||
except wsgi.Fault as fault:
|
||||
self.assertEqual(400, fault.status_int)
|
||||
|
||||
|
||||
class ResponseObjectTest(test.TestCase):
|
||||
def test_default_code(self):
|
||||
|
|
Loading…
Reference in New Issue