ca057 / x-err

Simple JavaScript module to create an Error with custom properties.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Simple JavaScript module to create an Error with custom properties.

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%