Socket
Socket
Sign inDemoInstall

@huolala-tech/custom-error

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huolala-tech/custom-error


Version published
Maintainers
1
Install size
5.39 kB
Created

Readme

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc