errorize

1.1.0 • Public • Published

Build Status

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));
 

Readme

Keywords

Package Sidebar

Install

npm i errorize

Weekly Downloads

22

Version

1.1.0

License

MIT

Last publish

Collaborators

  • nomilous