def __exit__(self, ex_type, ex_value, ex_traceback): if not ex_value: return True if isinstance(ex_value, exception.Forbidden): raise Fault( webob.exc.HTTPForbidden(explanation=ex_value.format_message())) elif isinstance(ex_value, exception.VersionNotFoundForAPIMethod): raise elif isinstance(ex_value, exception.Invalid): raise Fault( exception.ConvertedException( code=ex_value.code, explanation=ex_value.format_message())) 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_instantiate(self): exc = exception.ConvertedException(int(http.BAD_REQUEST), 'Bad Request', 'reason') self.assertEqual(exc.code, http.BAD_REQUEST) self.assertEqual(exc.title, 'Bad Request') self.assertEqual(exc.explanation, 'reason')
def test_instantiate_without_title_unknown_code(self): exc = exception.ConvertedException(499) self.assertEqual(exc.title, 'Unknown Client Error')
def test_instantiate_without_title_known_code(self): exc = exception.ConvertedException(int(http.INTERNAL_SERVER_ERROR)) self.assertEqual(exc.title, status_reasons[http.INTERNAL_SERVER_ERROR])