system-pri/backend/app/errors.py

14 lines
378 B
Python

import json
from apiflask import APIFlask
from werkzeug.exceptions import HTTPException
def register_error_handlers(app: APIFlask):
@app.errorhandler(HTTPException)
def handle_http_exception(e):
response = e.get_response()
response.data = json.dumps({"error": e.description})
response.content_type = "application/json"
return response