CustomError ·
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 {
}
const error = new MyError();
console.log(error instanceof Error);
console.log(error instanceof MyError);
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 {
}
const error = new MyError();
console.log(error instanceof Error);
console.log(error instanceof MyError);
console.log(error instanceof CustomError);
console.log(Object.prototype.toString.call(error));