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 = ; const ExampleError = ; throw ; // throws ExampleError: This is an example!
const CreateError = ; const ExampleError = ; try throw ; catch e console; // 'ExtraData'
License
MIT