使用flask-restful后errorhandler中间件无法拦截报错
找了半天源码,终于在Api类里这找到一句:
def handle_error(self, e):
"""Error handler for the API transforms a raised exception into a Flask
response, with the appropriate HTTP status code and body.
:param e: the raised Exception object
:type e: Exception
"""
got_request_exception.send(current_app._get_current_object(), exception=e)
if not isinstance(e, HTTPException) and current_app.propagate_exceptions:
exc_type, exc_value, tb = sys.exc_info()
if exc_value is e:
raise
else:
raise e
所以不是HttpException实例的错误只能在app config的propagate_exceptions是True的时候才能抛出。
于是在配置文件中加上
PROPAGATE_EXCEPTIONS = True
这文档我是翻遍了,真找不着这属性的介绍,我真麻了