Log any process errors:
-
uncaughtException
: an exception was thrown and not caught -
unhandledRejection
: a promise was rejected and not handled -
rejectionHandled
: a promise was rejected and handled too late -
multipleResolves
: a promise was resolved/rejected twice -
warning
: a warning was produced usingprocess.emitWarning()
const logProcessErrors = require('log-process-errors')
const undoSetup = lopProcessErrors.setup()
When any process errors occur, it will be logged using console.error()
.
The message will include detailed information about the error.
For warning
, console.warn()
will be used instead.
You can undo everything by firing the function returned by
onProcessError.setup()
(called undoSetup
in the example above).
TO BE DONE
You can override the default behavior by passing a custom function to the
handle
option.
onProcessError.setup({
handle({ eventName, promiseState, promiseValue, error, message }) {},
})
This can be useful if you want to use your own logger instead of the console.
The function's argument is an object with the following properties:
-
eventName
{string}
: can beuncaughtException
,unhandledRejection
,rejectionHandled
,multipleResolves
orwarning
-
error
{any}
is either:- value thrown by
uncaughtException
. Usually anError
instance, but not always. -
Error
instance emitted bywarning
.error.name
,error.code
anderror.detail
might be defined.
- value thrown by
-
promiseState
{string}
: whether promise wasresolved
orrejected
. ForunhandledRejection
,rejectionHandled
andmultipleResolves
. -
promiseValue
{any}
: value resolved/rejected by the promise. ForunhandledRejection
,rejectionHandled
andmultipleResolves
. -
message
{string}
: detailed message summing up all of the above.
By default, uncaughtException
will fire process.exit(1)
. This is the recommended behavior according to the
Node.js documentation.
You can disable this by setting the exitOnExceptions
option to false
:
onProcessError.setup({ exitOnExceptions: false })