-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessages.js
60 lines (57 loc) · 1.04 KB
/
messages.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
exports.ok = (res, payload) => {
res.setHeader('Content-Type', 'application/json');
const message = {
code: 0,
type: "ok",
payload: payload
};
res.json(message);
}
exports.error = (res, payload, err=1) => {
const message = {
type: "error",
code: err,
payload: payload
};
res.json(message);
}
exports.errors = {
generic: (res) => {
const message = {
type: "error",
code: 1,
payload: "Generic error"
};
res.json(message);
},
not_found: (res) => {
res.status(404);
const message = {
type: "error",
code: 2,
payload: "Not found error"
};
res.json(message);
},
connection: (res) => {
const message = {
type: "error",
code: 3,
payload: "Connection error"
};
res.json(message);
},
validation: function (res, array) => {
const message = {
type: "error",
code: 404,
payload: array
}
res.json(message);
}
}
exports.error_code = {
generic: 1,
not_found: 2,
connection: 3
}