Notoriously Psychedelic Modules

npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

x-err

1.1.0 • Public • Published

x-err

Simple JavaScript module to create an Error with custom properties.

npm npm

Installation

Install it via npm and save it as dependency: npm install --save x-err.

Usage

On construction, either provide an object, where all keys will be used as properties, or provide a string to provide a simple error message.

const XError = require('x-err');
 
try {
  throw new XError({ message: 'My error message.', foo: 'bar', baz: 42 });
} catch (error) {
  console.log(error.name); // 'XError
  console.log(error.message); // 'My error message.'
  console.log(error.foo); // 'bar'
  console.log(error.baz); // '42'
}
 
try {
  throw new XError('My error message.');
} catch (error) {
  console.log(error.name); // 'XError
  console.log(error.message); // 'My error message.'
}

Test

Run npm run test.

Resources

Based partly on:

License

GNU GENERAL PUBLIC LICENSE, see LICENSE.

install

npm i x-err

Downloadsweekly downloads

7

version

1.1.0

license

GPL-3.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability