Пример #1
0
    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.BadRequest):
            raise Fault(
                exception.ConvertedException(
                    code=ex_value.code, explanation=ex_value.format_message()))
        elif isinstance(ex_value, exception.Conflict):
            raise Fault(
                webob.exc.HTTPConflict(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.error("Fault thrown: %s", ex_value)
            raise ex_value
        elif isinstance(ex_value, webob.exc.HTTPException):
            LOG.error("HTTP exception thrown: %s", ex_value)
            raise Fault(ex_value)

        # We didn't handle the exception
        return False
Пример #2
0
    def test_call_fault(self):
        class MyException(object):
            code = 415
            explanation = 'test'

        my_exception = MyException()
        converted_exp = exception.ConvertedException(
            code=my_exception.code, explanation=my_exception.explanation)
        my_fault = wsgi.Fault(converted_exp)
        req = wsgi.Request.blank("/",
                                 method='POST',
                                 headers={'Content-Type': "unknow"})
        response = my_fault(req)
        self.assertEqual(415, response.status_int)