Performance: Error handler decorators
MEDIUM IMPACT
This affects how quickly errors are caught and handled during request processing, impacting response time and user experience.
from flask import Flask, jsonify app = Flask(__name__) @app.errorhandler(ZeroDivisionError) def handle_zero_division(e): return jsonify(error='Division by zero error'), 400 @app.route('/') def index(): 1 / 0 # triggers error handler
from flask import Flask app = Flask(__name__) @app.route('/') def index(): 1 / 0 # causes ZeroDivisionError # No error handler defined
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No error handler | N/A | N/A | Blocks response rendering due to server error | [X] Bad |
| Error handler decorator | N/A | N/A | Fast error response avoids blocking UI updates | [OK] Good |