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.

Package Sidebar

Install

npm i x-err

Weekly Downloads

5

Version

1.1.0

License

GPL-3.0

Last publish

Collaborators

  • christianost