2025-06-09 11:13:05 +00:00
|
|
|
import traceback
|
|
|
|
from flask import jsonify
|
|
|
|
from werkzeug.exceptions import HTTPException
|
|
|
|
from pydantic import ValidationError
|
|
|
|
import traceback
|
2025-06-24 19:08:08 +00:00
|
|
|
from bson.errors import InvalidId
|
|
|
|
|
2025-06-09 11:13:05 +00:00
|
|
|
|
|
|
|
def register_error_handlers(app):
|
|
|
|
@app.errorhandler(ValidationError)
|
|
|
|
def handle_validation_error(e):
|
|
|
|
return jsonify({"error": e.errors()}), 400
|
|
|
|
|
2025-06-24 19:08:08 +00:00
|
|
|
@app.errorhandler(InvalidId)
|
|
|
|
def handle_invalid_id_error(e):
|
|
|
|
return jsonify({"error": "Invalid ID format"}), 400
|
|
|
|
|
2025-06-09 11:13:05 +00:00
|
|
|
@app.errorhandler(HTTPException)
|
|
|
|
def handle_http_exception(e):
|
2025-06-24 19:08:08 +00:00
|
|
|
return jsonify({"error": e.description}), e.code
|
2025-06-09 11:13:05 +00:00
|
|
|
|
|
|
|
@app.errorhandler(Exception)
|
|
|
|
def handle_unexpected_exception(e):
|
|
|
|
app.logger.error(traceback.format_exc())
|
|
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
|
|
|