Python Pyramid exception_view异常详细信息

问题描述 投票:0回答:1

我正在使用Python Pyramid框架,并且正在使用异常视图。

例如

@exception_view_config(TypeError, renderer='json')
def type_error(exc, request):
    logger.info("There was a type error")

但是,异常对象没有关于错误发生位置的任何有用信息。在回溯中,它是excview_tween [tweens.py:43]

是否可以在此异常视图中获取更多相关信息?

python pyramid
1个回答
0
投票

您需要使用exc arg做些事情,无论是将其记录下来还是在视图中返回它。

class TypeError(Exception):
    def __init__(self, msg):
        self.msg = msg
@exception_view_config(TypeError, renderer='json')
def type_error(exc, request):
    response =  Response('Type Error: %s' % exc.msg)
    response.status_int = 500
    return response

您将需要使用exc引发异常。

raise TypeError("Here I am!")

请参见Custom Exception Views

© www.soinside.com 2019 - 2024. All rights reserved.