Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

err-code

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Issues
File Explorer

Advanced tools

err-code

Create an error with a code

    3.0.1latest

Version published
Maintainers
2
Weekly downloads
8,365,203
decreased by-11.53%

Weekly downloads

Readme

Source

err-code

NPM version Downloads Build Status Dependency status Dev Dependency status Greenkeeper badge

Create new error instances with a code and additional properties.

Installation

$ npm install err-code // or $ bower install err-code

The browser file is named index.umd.js which supports CommonJS, AMD and globals (errCode).

Why

I find myself doing this repeatedly:

var err = new Error('My message'); err.code = 'SOMECODE'; err.detail = 'Additional information about the error'; throw err;

Usage

Simple usage.

var errcode = require('err-code'); // fill error with message + code throw errcode(new Error('My message'), 'ESOMECODE'); // fill error with message + code + props throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' }); // fill error with message + props throw errcode(new Error('My message'), { detail: 'Additional information about the error' });

Pre-existing fields

If the passed Error already has a .code field, or fields specified in the third argument to errcode they will be overwritten, unless the fields are read only or otherwise throw during assignment in which case a new object will be created that shares a prototype chain with the original Error. The .stack and .message properties will be carried over from the original error and .code or any passed properties will be set on it.

Tests

$ npm test

License

Released under the MIT License.

Keywords

FAQs

What is err-code?

Create an error with a code

Is err-code popular?

The npm package err-code receives a total of 6,728,944 weekly downloads. As such, err-code popularity was classified as popular.

Is err-code well maintained?

We found that err-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 05 Feb 2021

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc