12

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?

ganduG
  • 615
  • 6
  • 18

1 Answers1

2

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

TheLittleNaruto
  • 8,325
  • 4
  • 54
  • 73