Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

panates/errorex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published