You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@huolala-tech/custom-error

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huolala-tech/custom-error

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

1.0.0
latest
npmnpm
Version published
Weekly downloads
188
22.88%
Maintainers
1
Weekly downloads
 
Created
Source

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]

FAQs

Package last updated on 20 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts