0

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)

1 Answer 1

1

Please add @app.errorhandler(HTTPException) before error_601

Documentation: https://flask.palletsprojects.com/en/1.1.x/errorhandling/#registering

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the tip, I missed the decorator from the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.