def __exit__(self, ex_type, ex_value, ex_traceback): if not ex_value: return True if isinstance(ex_value, exception.NotAuthorized): raise Fault(webob.exc.HTTPForbidden(explanation=ex_value.msg)) elif isinstance(ex_value, exception.Invalid): raise Fault( exception.ConvertedException(code=ex_value.code, explanation=ex_value.msg)) elif isinstance(ex_value, TypeError): exc_info = (ex_type, ex_value, ex_traceback) LOG.error('Exception handling resource: %s', ex_value, exc_info=exc_info) raise Fault(webob.exc.HTTPBadRequest()) elif isinstance(ex_value, Fault): LOG.info("Fault thrown: %s", ex_value) raise ex_value elif isinstance(ex_value, webob.exc.HTTPException): LOG.info("HTTP exception thrown: %s", ex_value) raise Fault(ex_value) # We didn't handle the exception return False
def test_standard_status_code(self): with mock.patch.dict(webob.util.status_reasons, {200: 'reason'}): exc = exception.ConvertedException(code=200) self.assertEqual('reason', exc.title)
def test_generic_status_code(self): with mock.patch.dict(webob.util.status_generic_reasons, {5: 'generic_reason'}): exc = exception.ConvertedException(code=599) self.assertEqual('generic_reason', exc.title)
def test_default_args(self): exc = exception.ConvertedException() self.assertNotEqual('', exc.title) self.assertEqual(http_client.INTERNAL_SERVER_ERROR, exc.code) self.assertEqual('', exc.explanation)
def test_default_args(self): exc = exception.ConvertedException() self.assertNotEqual('', exc.title) self.assertEqual(500, exc.code) self.assertEqual('', exc.explanation)