I'm writing an error handler for the RequestEntityTooLarge
exception in Flask such that the exception can be caught when it's raised in any views. I'd like to handle the exception by flashing a message on top of the page where it's raised.
Below is what I have so far, is there a way I can get the view where the exception is raised so I can re-render it?
@app.errorhandler(413)
def request_entity_too_large(error):
flash("File too large", "error-box")
return render_template(...) // it should re-render the view where exception is raised
Since Flask throws this exception automatically, I think try/catch blocks with custom exception class can be helpful here, I'm curious if there're other easier way to achieve this.