from flask import Flask, abort, Response
from werkzeug.exceptions import HTTPException
app = Flask(__name__)
@app.errorhandler(HTTPException)
def http_exception_handler(e: HTTPException):
msg = 'http_exception_handler is called.'
print(msg)
return msg
@app.route('/')
def index():
try:
abort(Response('I am the response passed to abort.', 400))
except Exception as e:
print(f'Raised error is an instance of HTTPException: {isinstance(e, HTTPException)}')
raise e
return 'Index successfully produced a response.'
In the code above, why is the registered handler for HTTPException not invoked when the abort function is called with a Response object? The execution of the code indicates the raised error by abort is an instance of HTTPException.