rest_utils.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:qinling 作者: openstack 项目源码 文件源码
def wrap_pecan_controller_exception(func):
    """Decorator for controllers method.

    This decorator wraps controllers method to manage pecan exceptions:
    In case of expected error it aborts the request with specific status code.
    """

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except exc.QinlingException as e:
            LOG.error('Error during API call: %s', six.text_type(e))
            return webob.Response(
                status=e.http_code,
                content_type='application/json',
                body=json.dumps(dict(faultstring=six.text_type(e))),
                charset='UTF-8'
            )

    return wrapped
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号