forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrSerializer.js
More file actions
executable file
·33 lines (31 loc) · 856 Bytes
/
errSerializer.js
File metadata and controls
executable file
·33 lines (31 loc) · 856 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
module.exports = function(err) {
if (!err || !err.stack)
return err;
var obj = {
message: err.message,
name: err.name,
stack: getFullErrorStack(err),
code: err.code,
signal: err.signal
};
return obj;
};
/*
* This function dumps long stack traces for exceptions having a cause()
* method. The error classes from
* [verror](https://github.com/davepacheco/node-verror) and
* [restify v2.0](https://github.com/mcavage/node-restify) are examples.
*
* Based on `dumpException` in
* https://github.com/davepacheco/node-extsprintf/blob/master/lib/extsprintf.js
*/
function getFullErrorStack(ex) {
var ret = ex.stack || ex.toString();
if (ex.cause) {
var cex = typeof (ex.cause) === 'function' ? ex.cause() : ex.cause;
if (cex) {
ret += '\nCaused by: ' + getFullErrorStack(cex);
}
}
return ret;
}