Error handler for either throwing locally or sending a bug ticket to a rest api
$ npm install err-hndlr
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: {...},
// }
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",
}
}
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.
-
jneidel/api.jneidel.com
- The api this module was built for. See for a usage example.
MIT © Jonathan Neidel