@huolala-tech/custom-error
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

CustomError · LICENSE

Used to fix the odd behaviors of native Error object inheritance code compiled to ES5.

Why?

If your code is compiled to ES5 target, you may encounter an unexpected behavior.

class MyError extends Error {
  // blah blah blah
}

const error = new MyError();

console.log(error instanceof Error); // true
console.log(error instanceof MyError); // false <!-- should be true

see https://babeljs.io/docs/en/caveats/#classes

Include

yarn add @huolala-tech/custom-error

or

npm install @huolala-tech/custom-error --save

Use the CustomError

import { CustomError } from '@huolala-tech/custom-error';

class MyError extends CustomError {
  // blah blah blah
}

const error = new MyError();

console.log(error instanceof Error); // true
console.log(error instanceof MyError); // true
console.log(error instanceof CustomError); // true
console.log(Object.prototype.toString.call(error)); // [object Error]

Readme

Keywords

none

Package Sidebar

Install

npm i @huolala-tech/custom-error

Weekly Downloads

39

Version

1.0.0

License

MIT

Unpacked Size

5.52 kB

Total Files

11

Last publish

Collaborators

  • qikang.yuan
  • huolala-fe
  • zhiyang-deng
  • wangdashuai
  • blucass
  • yanagieiichi