Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errorhandler not firing when DEBUG is False

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?

like image 565
ganduG Avatar asked Oct 29 '15 20:10

ganduG


1 Answers

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

like image 133
Andrii Ladyhin Avatar answered Oct 13 '22 07:10

Andrii Ladyhin