diff --git a/back/src/utils/standardResponse.js b/back/src/utils/standardResponse.js new file mode 100644 index 0000000..1deb381 --- /dev/null +++ b/back/src/utils/standardResponse.js @@ -0,0 +1,21 @@ +const responseCodes = { + 200: '请求成功', + 400: '请求参数错误', + 401: '未授权,请先登录', + 403: '没有访问权限', + 404: '请求的资源不存在', + 500: '服务器内部错误' +}; + +// 标准响应 +function standardResponse(code, message, data) { + return { + code: code, + message: message ?? responseCodes[code], + data: data + }; +} + +module.exports = { + standardResponse +}; \ No newline at end of file