21 lines
616 B
Python
21 lines
616 B
Python
|
import traceback
|
||
|
from flask import jsonify
|
||
|
from werkzeug.exceptions import HTTPException
|
||
|
from pydantic import ValidationError
|
||
|
import traceback
|
||
|
|
||
|
def register_error_handlers(app):
|
||
|
@app.errorhandler(ValidationError)
|
||
|
def handle_validation_error(e):
|
||
|
return jsonify({"error": e.errors()}), 400
|
||
|
|
||
|
@app.errorhandler(HTTPException)
|
||
|
def handle_http_exception(e):
|
||
|
return jsonify({"errror": e.description}), e.code
|
||
|
|
||
|
@app.errorhandler(Exception)
|
||
|
def handle_unexpected_exception(e):
|
||
|
app.logger.error(traceback.format_exc())
|
||
|
return jsonify({"error": str(e)}), 500
|
||
|
|
||
|
|