0.1.1 • Published 5 years ago

err-hndlr v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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:

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

apiAddress:

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:

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:

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:

The message used to call new Error( msg ).

data:

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

isExit:

Whenever the process should exit if the error is thrown.

Related

License

MIT © Jonathan Neidel

0.1.1

5 years ago

0.1.0

6 years ago