strong-error-handler/lib/clone.js

20 lines
515 B
JavaScript
Raw Normal View History

2016-08-17 19:03:17 +00:00
'use strict';
module.exports = cloneAllProperties;
/**
* clone the error properties to the data objects
* [err.name, err.message, err.stack] are not enumerable properties
* @param data Object to be altered
* @param err Error Object
*/
function cloneAllProperties(data, err) {
data.name = err.name;
data.message = err.message;
for (var p in err) {
if ((p in data)) continue;
data[p] = err[p];
}
// stack is appended last to ensure order is the same for response
data.stack = err.stack;
};