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 one argument, the name of the typed error.
import errorClass from 'error-class'
const HumanError = errorClass('HumanError')
const hungryError = new HumanError(`I'm hungry!`)
hungryError.name
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.constructor.name === 'HumanError'
thirstyError instanceof Error
thirstyError instanceof HumanError
License
This software is licensed under the MIT License.