我试图捕捉所有可能发生的异常,并将堆栈细节作为消息输出到FlaskRestPlus中。在
下面是一个示例,如果我引发自定义异常,如RootException
,则可以使用它。但我没能让它与BaseException
或任何其他可能起到包罗万象作用的东西一起工作。我也没有找到将堆栈(或原始错误消息)输出到消息体的方法。在
@api.errorhandler(RootException)
def handle_root_exception(error):
return {'message': 'Here I want the original error message'}, 500
如有任何建议,我将不胜感激。文档似乎不太清楚:https://flask-restplus.readthedocs.io/en/stable/errors.html
要创建通用错误处理程序,可以使用:
堆栈跟踪捕获
要自定义堆栈跟踪处理,请参见Python When I catch an exception, how do I get the type, file, and line number?。在
堆栈跟踪数据捕获示例
^{pr2}$函数
get_type_or_class_name
是一个助手,它获取对象的类型名,或者在类的情况下,返回类名。在通常还提供
HTTPException
处理程序:相关问题 更多 >
编程相关推荐