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 errorhandler
s. 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?
You should add
app.config['PROPAGATE_EXCEPTIONS'] = True
It happens because flask overrides the usual error handling code (for all routes under its control).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With