2.3.2 • Published 6 years ago

errorex v2.3.2

Weekly downloads
2,238
License
MIT
Repository
github
Last release
6 years ago

ErrorEx

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

'Extensible Error Class' implementation and predefined additional error types for javascript.

Installation

$ npm install errorex --save

Usage

var {ErrorEx, RangeError} = require('errorex');

var error = new erx.RangeError('Value out of range')
        .setMinValue(1)
        .setMaxValue(5);
console.log(error.message);                    // Value out of range
console.log(error instanceof Error);           // true
console.log(error instanceof erx.RangeError);  // true
console.log(error.toString());                 // RangeError: Value out of range
console.log(error.minValue);                   // 1
console.log(error.maxValue);                   // 5
console.log(error.stack);                      // Prints stack trace

Extending custom error classes in ES6

class MyError extends ErrorEx {
 constructor(...args) {
   super(...args);
   this.myproperty = 1000;
 }
 
 setFoo(val) {
   this.set('foo', val);
 }
}


throw new MyError('My message %d', 10)
.setFoo('fooooo')
.set({
  prop1: 1,
  prop2: 2
});

Extending custom error classes in ES5

function MyError() {
  ErrorEx.apply(this, arguments);
  this.myproperty = 1000;
}
MyError.prototype = Object.create(ErrorEx.prototype);
MyError.prototype.constructor = MyError;
MyError.prototype.setFoo = function(val) {
  this.set('foo', val);
};


throw new MyError('My message %d', 10).setFoo('fooooo');

Predefined error classes

  • ErrorEx: Base error class

  • ArgumentError: Extending from ErrorEx

  • RangeError: Extending from ErrorEx

  • HttpError: Extending from ErrorEx

  • HttpClientError: Extending from HttpError

  • HttpServerError: Extending from HttpError

Node Compatibility

  • node >= 0.10;

License

MIT

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago