生产模式下的烧瓶忽略@ app.errorhandler

时间:2018-06-21 18:00:29

标签: flask

在调试模式下,@ app.errorhandler起作用,但是在生产环境中,我必须设置PROPOGATE_EXCEPTIONS = 1才能获得该行为。我想知道为什么(安全原因?)。其次,在设置了PROPOGATE_EXCEPTIONS的情况下,是否仍会获得错误日志记录(当针对给定的异常没有烧瓶错误处理程序时)?从Flask源代码的外观来看,它不是,并且想知道在这种情况下如何获取日志。我最初的想法是为Exception设置一个flask错误处理程序,该处理程序更通用,应该在最后一次被击中,在该日志中,我登录并返回500。这是正确的模式吗?

我正在使用Flask 1.0.2。

1 个答案:

答案 0 :(得分:1)

罪魁祸首是flask_restful覆盖了烧瓶的错误处理行为。在https://github.com/flask-restful/flask-restful/issues/280#issuecomment-280648790找到的解决方法恢复了flask的错误处理。

handle_exceptions = app.handle_exception
handle_user_exception = app.handle_user_exception
api = Api(app)
app.handle_user_exception = handle_exceptions
app.handle_user_exception = handle_user_exception
相关问题