flask-dashboard / Flask-MonitoringDashboard

Automatically monitor the evolving performance of Flask/Python web services.
http://flask-monitoringdashboard.readthedocs.io/
MIT License
767 stars 159 forks source link

Fix status code incorrect when abort() function is used #454

Closed BattlefieldDuck closed 6 months ago

BattlefieldDuck commented 6 months ago

When a user calls the abort(400) function, the Flask monitoring dashboard mistakenly records a status code of 500 instead of the expected 400.

from flask import abort

@app.route('/search', methods=['GET'])
def search():
    abort(400)  # <- raise HTTPException

The underlying issue is that the HTTPException is being caught as a generic Exception, which is then incorrectly returned as a 500 error.

This pull request addresses and resolves this issue.

For more information on the Flask abort() function: https://flask.palletsprojects.com/en/2.3.x/errorhandling/#custom-error-pages

JohannesLC commented 6 months ago

Hey @BattlefieldDuck Thank you for the fix!