1.1.0 • Published 8 years ago
nu-error v1.1.0
nu-error
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
1.1.0
8 years ago