server_response.js
802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* @Author: huyue
* @Date: 2021-09-06 15:04:10
* @Last Modified by: huyue
* @Last Modified time: 2021-09-06 15:04:30
*/
const { SUCCESS, ERROR } = require("./server_response_code");
module.exports = class ServerResponse {
constructor(status, msg, data) {
this.status = status;
this.msg = msg;
this.data = data;
}
isSuccess() {
return this.status === SUCCESS;
}
getStatus() {
return this.status;
}
getData() {
return this.data;
}
getMsg() {
return this.msg;
}
static Success(data = null,respo = SUCCESS) {
const { code,message } = respo
return new ServerResponse(code,message, data);
}
static Error(respo = ERROR) {
const { code=ERROR.code,message,data } = respo
return new ServerResponse(code,message, data);
}
};