feat: 标准响应函数
This commit is contained in:
parent
9ccd1c7d88
commit
ca0c07857e
21
back/src/utils/standardResponse.js
Normal file
21
back/src/utils/standardResponse.js
Normal file
@ -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
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user