Socket
Socket
Sign inDemoInstall

es6-error

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    es6-error

Easily-extendable error for use with ES6 classes


Version published
Weekly downloads
5.3M
increased by2.15%
Maintainers
1
Install size
10.4 kB
Created
Weekly downloads
 

Readme

Source

es6-error

npm version Build Status

An easily-extendable error class for use with ES6 classes (or ES5, if you so choose).

Tested in Node 4.0, Chrome, and Firefox.

Why?

I made this because I wanted to be able to extend Error for inheritance and type checking, but can never remember to add Error.captureStackTrace(this, this.constructor.name) to the constructor or how to get the proper name to print from console.log.

ES6 Usage


import ExtendableError from 'es6-error';

class MyError extends ExtendableError {
  // constructor is optional; you should omit it if you just want a custom error
  // type for inheritance and type checking
  constructor(message = 'Default message') {
    super(message);
  }
}

export default MyError;

ES5 Usage


var util = require('util');
var ExtendableError = require('es6-error');

function MyError(message) {
  message = message || 'Default message';
  ExtendableError.call(this, message);
}

util.inherits(MyError, ExtendableError);

module.exports = MyError;

Known Issues

  • Uglification can obscure error class names (#31)
Todo
  • Better browser compatibility
  • Browser tests

Keywords

FAQs

Last updated on 03 Jan 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc