Performance: API error handling
MEDIUM IMPACT
This affects the responsiveness and stability of API endpoints, impacting how quickly errors are detected and communicated to clients.
from flask import Flask, jsonify app = Flask(__name__) @app.errorhandler(ZeroDivisionError) def handle_zero_division(error): return jsonify({'error': 'Division by zero error'}), 400 @app.route('/data') def get_data(): data = 1 / 0 # This will raise ZeroDivisionError return jsonify({'data': data})
from flask import Flask, jsonify app = Flask(__name__) @app.route('/data') def get_data(): try: # Simulate data fetching data = 1 / 0 # This will raise ZeroDivisionError return jsonify({'data': data}) except Exception as e: return jsonify({'error': str(e)}), 500
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Broad try-except in route | 0 (API only) | 0 | 0 | [X] Bad |
| Specific Flask errorhandler | 0 (API only) | 0 | 0 | [OK] Good |