Socket
Socket
Sign inDemoInstall

error-base

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

error-base

Create custom Error classes.


Version published
Weekly downloads
128
increased by23.08%
Maintainers
1
Weekly downloads
 
Created
Source

error-base NPM version Build Status

Create custom Error classes.

Install with npm:

$ npm i error-base --save

Usage

var errorBase = require('error-base');

// Create a new HelperError that takes additional options.
var HelperError = errorBase('HelperError', function (msg, options) {
  this.message = msg;
  this.options = options || {};
});

try {
  // Throw a HelperError given the custom arguments
  throw new HelperError('some error message', {
    helper: 'helper-name',
    foo: 'bar'
  });
} catch (err) {
  console.log(err.message);
  //=> 'some error message'

  console.log(err.options);
  //=> { helper: 'helper-name', foo: 'bar' }
}

API

errorBase

Code modified from http://stackoverflow.com/a/27925672/914583

Params

  • name {String}: Name of new Error Class
  • init {Function}: Function to call when creating new Error
  • capture {Boolean}: Optional parameter to determine if the stack trace should be captured or not. (Defaults to true)
  • returns {Function}: new Error Class

Example

var CustomError = errorBase('CustomError', function (msg) {
  this.msg = msg;
});

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Brian Woodward

License

Copyright © 2016 Brian Woodward Released under the MIT license.


This file was generated by verb on February 10, 2016.

FAQs

Package last updated on 10 Feb 2016

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