I am currently working on an app using flask. Whenever I am encountering an error, I am raising it using abort, for example abort(404).

I created a new blueprint for error handling, and included the following files in the errors blueprint:


from flask import Blueprint

bp = Blueprint('errors', __name__)

from app.errors import handlers


from app.errors import bp
from flask import jsonify, make_response

def not_found_error():
    return make_response(jsonify({"error: ", "Not found"}), 404)

I also registered the blueprint as follows:


from app.errors import bp as errors_bp

However, when I am encountering the error, I get an HTML response back instead of the JSON response. If I include the errorhandler in the same blueprint as the APIs, it works fine. How do I have a separate error handler blueprint?

0 Answers