forked from randomBrainstormer/MMM-GoogleCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
31 lines (29 loc) · 787 Bytes
/
helpers.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
/**
* Encode query params
*/
function encodeQueryData(data) {
const ret = [];
for (let d in data) {
ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
}
return ret.join("&");
}
function formatError(err) {
if (err instanceof Error) {
return `Error: ${err.name}\nMessage: ${err.message}\nStack: ${err.stack}`;
} else if (typeof err === "object") {
try {
return `Non-Error Object: ${JSON.stringify(err, null, 2)}`;
} catch (stringifyError) {
// Just in case JSON.stringify fails (e.g., due to circular references)
return `Non-Error Object (stringify failed): ${String(err)}`;
}
} else {
// other types (e.g., strings, numbers)
return String(err);
}
}
module.exports = {
encodeQueryData,
formatError
};