custom-error-class

Straightforward ES6 class you can extend to make proper custom errors

MIT 1 个版本
安装
npm install custom-error-class
yarn add custom-error-class
pnpm add custom-error-class
bun add custom-error-class
README

custom-error-class

Straightforward ES6 class you can extend to make custom errors that are all instanceof Error with proper stacks.

npm install custom-error-class

Usage

const CustomError = require('custom-error-class')

class MyError extends CustomError {
  constructor () {
    super('an error happened')
    this.code = 'SOME_CODE'
  }
}

// Use this error as you normally would.
throw new MyError()

Credits to @pfrazee who wrote most of it.

License

MIT

版本列表
1.0.0 2019-01-24