simple-errors

Errors constructor for simple error handling.

BSD 7 个版本
安装
npm install simple-errors
yarn add simple-errors
pnpm add simple-errors
bun add simple-errors
README

#simple-errors Factory methods for easy error handling.

##Installation

npm install simple-errors

##Usage Just make sure to require the module somewhere in your code (only once)

require('simple-errors');

Then use the factory methods for creating errors:

//simplest of errors
var err = Error.create();

//with message
var err = Error.create('foo');
console.log(err.message === 'foo'); //prints true

//with data
var err = Error.create('foo', { foo: 'bar' });
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true

//with data and inner error
var err = Error.create('foo', { foo: 'bar' }, err);
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true
console.log(err.inner === err); //prints true

//helper for status codes (for use with connect & express)
var err = Error.http(500);
console.log(err.status === 500); //prints true

//helper for status codes, with message, data and error
var err = Error.http(500, 'foo', {foo: 'bar'}, err);
console.log(err.status === 500); //prints true
console.log(err.message === 'foo'); //prints true
console.log(err.foo === 'bar'); //prints true
console.log(err.inner === err); //prints true

//helper method for turning the Error instance into a json object
var err = Error.create();
var obj = Error.toJson(err); //use this to print the entire error with stack.

版本列表
1.0.1 2015-03-06
1.0.0 2014-11-10
0.0.5 2014-07-21
0.0.4 2013-02-25
0.0.3 2013-01-22
0.0.2 2013-01-11
0.0.1 2013-01-11