-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathglobal_functions.js
More file actions
35 lines (28 loc) · 844 Bytes
/
global_functions.js
File metadata and controls
35 lines (28 loc) · 844 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
pe = require('parse-error'); //parses error so you can read error message and handle them accordingly
to = function (promise) {
return promise
.then(data => {
return [null, data];
}).catch(err => [pe(err)])
};
TE = function (errMessage, log) {
if (log === true) {
console.error(errMessage);
}
throw new Error(errMessage);
};
ReE = function (res, err, code) {
if (typeof err == 'object' && typeof err.message != 'undefined') {
err = err.message;
}
if (typeof code !== 'undefined') res.statusCode = code;
return res.json({ success: false, error: err });
};
ReS = function (res, data, code) {
let sendData = { success: true };
if (typeof data == 'object') {
sendData = Object.assign(data, sendData);
}
if (typeof code !== 'undefined') res.statusCode = code;
return res.json(sendData);
};