Socket
Socket
Sign inDemoInstall

error-subclass

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-subclass

Extendable Error Class


Version published
Weekly downloads
199
decreased by-33.22%
Maintainers
1
Weekly downloads
 
Created
Source

ErrorSubclass

NPM

Build Status

Dependencies DevDependencies

A JavaScript class that makes Error subclassable. It inherits from Error (in all the right ways), so that you can safely and easily create your own Error subclasses.

The provided class handles all the craziness for preserving stack traces and other things so that you don't have to worry about it. Create a class that inherits from it and you're good to go.

  • instanceof Error
  • instanceof <your subclass>
  • stack traces
  • .name === <name of subclass>
  • .toString()

Usage

import ErrorSubclass from 'error-subclass';

class MyError extends ErrorSubclass {

  static displayName = 'MyError'; // optional. survives minification

  // Add extra properties/methods if desired:

  get code() {
    return 'MYERROR';
  }

}

// later...
throw new MyError('error message');

License

MIT

FAQs

Package last updated on 22 Mar 2017

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc