errorize
v1.1.0
Published
Ensure it is (or make it an) error
Downloads
88
Readme
errorize
Ensure it is (or make it an) error.
Because some folks throw strings or other stuff.
npm install errorize --save
var errorize = require('errorize');
It returns the object passed as an error
var e = errorize(object);
It preserves the object's properties into the error
var obj = {
key: 'value'
};
var e = errorize(obj);
e.key == 'value'
It decorates functions to ensure arg1 (if present) is an error
.catch(errorize(function(e) {}))
// or
functionWithCallback('args', errorize(function(e, result) {}))
It can transform error to (json) serializable object
JSON.stringify(errorize.encode(e));
It can include a partial stack in the translation
JSON.stringify(errorize.encode(e, 3));