-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
31 lines (30 loc) · 1.18 KB
/
Copy pathutils.js
File metadata and controls
31 lines (30 loc) · 1.18 KB
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
export function replaceInString(str, obj) {
let result = String(str);
for (let key in obj) {
result = result.replace(new RegExp(`\\$${key}`, "g"), obj[key]);
}
return result;
}
export function errorWrapper(callback, { exitOnError = true } = {}) {
return async function (...args) {
try {
return await callback(...args);
} catch (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data);
console.log(error.response.status);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
if (exitOnError) process.exit(1);
}
}
}