2.0.2 • Published 6 years ago

error-class v2.0.2

Weekly downloads
1,680
License
MIT
Repository
github
Last release
6 years ago

Error Class

Build Status npm Version License

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 // 'foobar'

Details

const errorClass = require('error-class')
const HumanError = errorClass('HumanError')

const hungryError = new HumanError('I\'m hungry!')
hungryError.message // 'I'm hungry!'
hungryError.stack // Platform-specific error stack trace.
hungryError.hasOwnProperty('name') // false
hungryError.hasOwnProperty('message') // true
hungryError.hasOwnProperty('stack') // true

// Just like native errors, it doesn't require using `new`.
const thirstyError = HumanError('I\'m thirsty!')
Object.keys(thirstyError).length === 0 // True, all properties are non-enumerable.
Object.keys(Object.getPrototypeOf(instance)).length === 0 // Prototype non-enumerable.
thirstyError.constructor === HumanError // True.
thirstyError instanceof Error // True, errors inherit from native `Error` class.
thirstyError instanceof HumanError // Also true, of course.

License

This software is licensed under the MIT License.

2.0.2

6 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago