35 lines
831 B
Python
35 lines
831 B
Python
"""
|
||
响应工具 - 统一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字段中
|
||
|