-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.26 KB
/
index.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
var cycle = require('cycle');
module.exports.ErrorSponge = ErrorSponge;
function ErrorSponge(options) {
options = options || {};
var unserializableList = options.unserializableErrorProperties || [];
var len = unserializableList.length;
this.unserializableErrorProperties = {};
for (var i = 0; i < len; i++) {
this.unserializableErrorProperties[unserializableList[i]] = true;
}
}
ErrorSponge.prototype.dehydrate = function (error, includeStackTrace) {
var dehydratedError;
if (!error || typeof error == 'string') {
dehydratedError = error;
} else {
dehydratedError = {
message: error.message
};
if (includeStackTrace) {
dehydratedError.stack = error.stack;
}
for (var i in error) {
if (!this.unserializableErrorProperties[i]) {
dehydratedError[i] = error[i];
}
}
}
return cycle.decycle(dehydratedError);
};
ErrorSponge.prototype.hydrate = function (error) {
var hydratedError = null;
if (error != null) {
if (typeof error == 'string') {
hydratedError = error;
} else {
hydratedError = new Error(error.message);
for (var i in error) {
if (error.hasOwnProperty(i)) {
hydratedError[i] = error[i];
}
}
}
}
return hydratedError;
};