Error Class
This module provides typed errors that closely emulate the native Error
class to a pedantic degree.
$ npm install error-class
Usage
The default export is a function that accepts only one argument, the name of the typed error.
const errorClass = require('error-class')
const SpecialError = errorClass('SpecialError')
const instance = new SpecialError('foobar')
instance.message
Details
const errorClass = require('error-class')
const HumanError = errorClass('HumanError')
const hungryError = new HumanError('I\'m hungry!')
hungryError.message
hungryError.stack
hungryError.hasOwnProperty('name')
hungryError.hasOwnProperty('message')
hungryError.hasOwnProperty('stack')
const thirstyError = HumanError('I\'m thirsty!')
Object.keys(thirstyError).length === 0
Object.keys(Object.getPrototypeOf(instance)).length === 0
thirstyError.constructor === HumanError
thirstyError instanceof Error
thirstyError instanceof HumanError
License
This software is licensed under the MIT License.