Utils
A small library that has common code to be shared across wagel modules. It currently supports error handling / errors, middlewares and common API methods.
Installation
List tokens: npm token list Create token: npm token create --read-only Delete token: npm token delete
Read more
https://docs.npmjs.com/getting-started/working_with_tokens
https://docs.npmjs.com/files/npmrc
"utils": "git+https://874d51582870893d902b28357b46aea94f83b653:x-oauth-basic@github.com/wagel/utils.git"
http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
`http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
Usage
Errors module
const utils = require('utils')
const errors = utils.errors
- Throw errors
throw new errors.ValidationError('Password too short.')
throw new errors.AuthError('Wrong credentials.')
throw new errors.BadRequestError('Email field is missing.')
throw new errors.InternalFailureError('Something went wrong.')
Middleware module
const utils = require('utils')
const middlewares = utils.middlewares
- Register error handler
middlewares.errorHandler(app)(process.env.NODE_ENV)
API wrapper module
const utils = require('utils')
const wagelAPI = utils.wagelAPI
Tests
npm test