This package has been deprecated

Author message:

abandoned

nu-error

1.1.0 • Public • Published

nu-error

npm version Codecov Dependency Status

Easily create custom errors in Node.js

Install

npm install nu-error

Usage

nu-error exposes a single factory function.

CreateError(name: String) => errorFunction: Function, throws TypeError

Creates and returns an errorFunction bound to name.

errorFunction(message: String, extra: Object, constructorOpt: Function) => Error

  • message - The error message.
  • extra - An object to assign to the error.
  • constructorOpt - See Error.captureStackTrace.

Example

const CreateError = require('nu-error');
 
const ExampleError = CreateError('ExampleError');
 
throw ExampleError('This is an example!'); // throws ExampleError: This is an example!
const CreateError = require('nu-error');
 
const ExampleError = CreateError('ExampleError');
 
try {
  throw ExampleError('!', {
    extra: 'ExtraData',
  });
} catch (e) {
  console.log(e.extra); // 'ExtraData'
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i nu-error

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • npm