1 | [ ![Codeship Status for wagel/utils](https://app.codeship.com/projects/02055060-8f32-0135-e440-123d7e857dcf/status?branch=master)](https://app.codeship.com/projects/249922)
|
2 |
|
3 | Utils
|
4 | =========
|
5 |
|
6 | A small library that has common code to be shared across wagel modules. It currently supports error handling / errors, middlewares and common API methods.
|
7 |
|
8 | ## Installation
|
9 |
|
10 | List tokens: npm token list
|
11 | Create token: npm token create --read-only
|
12 | Delete token: npm token delete
|
13 |
|
14 | Read more
|
15 |
|
16 | `https://docs.npmjs.com/getting-started/working_with_tokens`
|
17 |
|
18 | `https://docs.npmjs.com/files/npmrc`
|
19 |
|
20 | `"utils": "git+https://874d51582870893d902b28357b46aea94f83b653:x-oauth-basic@github.com/wagel/utils.git"`
|
21 |
|
22 | `http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules`
|
23 |
|
24 | `http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
|
25 |
|
26 |
|
27 | ## Usage
|
28 |
|
29 | # Errors module
|
30 |
|
31 | `const utils = require('utils')`
|
32 |
|
33 | `const errors = utils.errors`
|
34 |
|
35 | * Throw errors
|
36 |
|
37 | `throw new errors.ValidationError('Password too short.')`
|
38 |
|
39 | `throw new errors.AuthError('Wrong credentials.')`
|
40 |
|
41 | `throw new errors.BadRequestError('Email field is missing.')`
|
42 |
|
43 | `throw new errors.InternalFailureError('Something went wrong.')`
|
44 |
|
45 | # Middleware module
|
46 |
|
47 | `const utils = require('utils')`
|
48 |
|
49 | `const middlewares = utils.middlewares`
|
50 |
|
51 | * Register error handler
|
52 |
|
53 | `middlewares.errorHandler(app)(process.env.NODE_ENV)`
|
54 |
|
55 |
|
56 | # API wrapper module
|
57 | `const utils = require('utils')`
|
58 | `const wagelAPI = utils.wagelAPI`
|
59 |
|
60 | ## Tests
|
61 |
|
62 | `npm test`
|