node-usererror
User errors for Node.js
This Node.js module extends Error class by adding a code
property. This allows you to easily
identify instances at your error handler, just like system errors.
Requirements
All you need to get it with you Node.js. If you're using a Linux system, you can use node-install for an easy installation.
Installation
To use have this module installed, just follow the next instructions.
NPM
ૐ » your-project-dir λ npm install node-usererror
GIT
ૐ » your-project-dir λ git clone https://github.com/IvanGaravito/node-usererror.git
Usage
Just require the module and use it like if it were the Error class:
var UserError =trythrow 'My own error' 'EOWN'catch errif errcode === 'EOWN'console // Outputs: { [Error: My own error] code: 'EOWN', message: 'My own error' }elseconsoleprocess
API
Example
var UserError =// ...throw 'My own error' 'EOWN'
Error
node-usererror~UserError ⇐ Kind: inner class of node-usererror
Extends: Error
new UserError(message, code)
Param | Type | Description |
---|---|---|
message | string |
The error message |
code | any |
The error code you want to use for this error |
License
The MIT License (MIT)
Copyright (c) 2016 Ivan Garavito ivangaravito@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.