JSPM

  • Created
  • Published
  • Downloads 173439
  • Score
    100M100P100Q167354F
  • License Apache-2.0

Log all process errors: uncaught exceptions, warnings and improperly handled promises

Package Exports

  • log-process-errors

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (log-process-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

downloads last commit license npm node JavaScript Style Guide eslint-config-standard-prettier-fp

Log any process errors:

Usage

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).

Example output

TO BE DONE

Custom handling

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 be uncaughtException, unhandledRejection, rejectionHandled, multipleResolves or warning
  • error {any} is either:
  • promiseState {string}: whether promise was resolved or rejected. For unhandledRejection, rejectionHandled and multipleResolves.
  • promiseValue {any}: value resolved/rejected by the promise. For unhandledRejection, rejectionHandled and multipleResolves.
  • message {string}: detailed message summing up all of the above.

Exiting on uncaught exceptions

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 })