Register errorhandler Functions
Customize responses for 404 and 500.
Beyond the Default Page
Flask shows a plain error page out of the box. You can replace it by registering your own errorhandler for any status code.
The errorhandler Decorator
You attach a function to a code with a decorator. This handler runs whenever that error happens anywhere in your app.
@app.errorhandler(404)
def not_found(e):
return "Nothing here", 404All lessons in this course
- abort and HTTP Error Codes
- Register errorhandler Functions
- Raise Custom Exception Classes
- Uniform JSON Error Envelopes