Reputation: 150
How would I go about adding a custom HTTP error? From what I understand error codes in the 6XX and 7XX class can be used for that purpose, but Flask doesn't let me handle these errors as it says that this(601) isn't a recognized HTTP error.
EDIT: This is the correct Code:-
from werkzeug.exceptions import HTTPException
@errors.errorhandler(HTTPException)
def error_601(HTTPException):
return render_template('errors/601.html'), 601
class No_results_found(HTTPException):
code = 601
description = '<p>No_results_found.</p>'
errors.register_error_handler(No_results_found, error_601)
Upvotes: 0
Views: 618
Reputation: 1873
Please add @app.errorhandler(HTTPException)
before error_601
Documentation: https://flask.palletsprojects.com/en/1.1.x/errorhandling/#registering
Upvotes: 1