errorhandler not firing when DEBUG is False

蓝咒 提交于 2020-05-11 05:22:38

问题


I'm using errorhandlers to catch and handle certain kinds of exceptions:

@app.errorhandler(CustomException)
def handle_custom_exception(error):
    return redirect('redirect-path', code=301)

This works correctly when DEBUG is True, which implicitly sets PROPAGATE_EXCEPTIONS to True as well. When DEBUG is False though, PROPAGATE_EXCEPTIONS defaults to False and Flask returns a 500 for all errors thrown, ignoring the registered errorhandlers. Setting PROPAGATE_EXCEPTIONS to True corrects the error handling in this case.

What i'm wondering about is:

  • Is it safe to have PROPAGATE_EXCEPTIONS enabled in production? Are there any side effects I should be concerned about?

  • Why does Flask have different default values for this config in debug vs non-debug?


回答1:


You should add app.config['PROPAGATE_EXCEPTIONS'] = True It happens because flask overrides the usual error handling code (for all routes under its control).



来源:https://stackoverflow.com/questions/33423580/errorhandler-not-firing-when-debug-is-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!