Flask has a good error handler by using abort()
or when the error truly occurred.
From Flask documentation there is an example for error 404 handler:
@app.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404
So, I tried to create custom error code like
if False:
abort(777)
@app.errorhandler(777)
def something_is_wrong(error):
return render_template('777.html'), 777
But it does not work and the Werkzeug debugger says: LookupError: no exception for 777
I found this question which says I should do it like this:
if False:
return '777 error', 777
Unfortunately, the code above produce white-screen, even the Werkzeug debugger does not come out
I know I can simply do:
if False:
return render_template('777.html')
But it will make the code cleaner if I use the abort()
. Is there any way to create custom error code?