-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror.js
32 lines (32 loc) · 929 Bytes
/
error.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
const PlugableError = class PlugableError extends Error {
constructor(code, message, ...contexts) {
var context, i, key, len, value;
if (Array.isArray(message)) {
message = message.filter(function (line) {
return !!line;
}).join(' ');
}
message = `${code}: ${message}`;
super(message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, PlugableError);
}
this.code = code;
for (i = 0, len = contexts.length; i < len; i++) {
context = contexts[i];
for (key in context) {
if (key === 'code') {
continue;
}
value = context[key];
if (value === void 0) {
continue;
}
this[key] = Buffer.isBuffer(value) ? value.toString() : value === null ? value : JSON.parse(JSON.stringify(value));
}
}
}
};
export default (function () {
return new PlugableError(...arguments);
});