ai-business-write/utils/response.py
2025-12-04 14:41:20 +08:00

35 lines
831 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
响应工具 - 统一API响应格式
"""
from flask import jsonify
from datetime import datetime
def success_response(data=None, msg="ok"):
"""成功响应"""
return jsonify({
"code": 0,
"data": data,
"msg": msg,
"path": None,
"extra": None,
"timestamp": str(int(datetime.now().timestamp() * 1000)),
"errorMsg": "",
"isSuccess": True
})
def error_response(code, error_msg, data=None):
"""错误响应"""
return jsonify({
"code": code,
"data": data,
"msg": "error",
"path": None,
"extra": None,
"timestamp": str(int(datetime.now().timestamp() * 1000)),
"errorMsg": error_msg,
"isSuccess": False
}), 200 # 即使错误也返回200状态码错误信息在code字段中