npm.io
1.0.2 • Published 7 years ago

customized-errors

Licence
MIT
Version
1.0.2
Deps
3
Size
6 kB
Vulns
0
Weekly
0

app-error

custom app error

install

# npm
npm install customized-errors

# yarn
yarn add customized-errors

Test

npm test

# or with yarn 
yarn run test

usage

const {TooManyRequestsError} = require('./error')

try {
    throw new TooManyRequestsError({message: 'You have exceeded your API rate limit', type: 'E_EXCEEDED_API_RATE_LIMIT', details:{limitCounts: 100, currentRequestCounts: 101}})
} catch (error) {
    console.error(error.message)
    console.log()
    console.error(error)
}

// prints:

// You have exceeded your API rate limit

// { name: 'TooManyRequestsError',
//   code: 'E4429',
//   type: 'E_EXCEEDED_API_RATE_LIMIT',
//   details: { limitCounts: 100, currentRequestCounts: 101 },
//   message: 'You have exceeded your API rate limit',
//   statusCode: 429 }

TODO

  1. add test
  2. update readme
  3. ...

Dependencies

  1. statuses