npm

Need private packages and team management tools?Check out npm Orgs. »

err-hndlr

0.1.1 • Public • Published

err-hndlr

Error handler for either throwing locally or sending a bug ticket to a rest api

Travis Build Status License MIT Npm Downloads

Install

Npm Version

$ npm install err-hndlr

Usage

const errHndlr = require( "err-hndlr" );
 
errHndlr.init(
  process.argv[2] === "--debug",
  "https://api.jneidel.com/errors/submit",
  {
    applicationId: "1337"
  }
)
 
errHndlr.throw(
  "smt went wrong",
  {
    env: {...},
  },
  false
)
 
// If --debug flag was passed:
//=> Error: something went wrong
 
// If --debug flag was not passed:
// POST https://api.jneidel.com/error/submit
//    {
//      applicationId: "1337",
//      error: {
//        msg: "smt went wrong",
//        stack: "...",
//      },
//      env: {...},
//    }

API

init( isThrow, apiAddress, data, options )

Globally initializes the error handler. This function has to be run before throwing any errors.

errHndlr.init(
  false,
  http://api.jneidel.com/errors/submit,
  { id: "1337" },
)

isThrow:

Default: true Type: boolean

Whenever errors should be thrown locally (true) or be sent to the rest api (false).

apiAddress:

Type: string

Rest api endpoint where error requests should be sent if isThrow=false. The data will be sent in the body of the POST request.

data:

Default: {} Type: object

The data that will be sent along on every request. You might want to include device specific data (os, etc.) and application data (name, version, etc.) here.

options:

Default: {} Type: object

Currently supported options are:

app:

Require your package.json through the app option to include the app's name and version in every request.

// options:
{
  app: require( "../package.json" )
}
// POST request:
{
  ...
  app: {
    name: "err-hndlr",
    version: "0.0.1",
  }
}

os:

Pass a truthy value to include the os.type() and os.platform() in every request.

// options:
{
  os: true
}
// POST request:
{
  ...
  os: {
    type: "Linux",
    platform: "linux",
  }
}

throw( msg, data, isExit )

errHndlr.throw(
  "something went wrong",
  data: {
    env: {...}
  },
  false,
).catch( err => {...} ) // To handle connection errors (ECONNREFUSED)

msg:

Type: string

The message used to call new Error( msg ).

data:

Default: {} Type: object

Data to be include on this specific request. Might include environmental variables, state, etc.

isExit:

Default: false Type: boolean

Whenever the process should exit if the error is thrown.

Related

License

MIT © Jonathan Neidel

install

npm i err-hndlr

Downloadsweekly downloads

5

version

0.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability