项目作者: papb

项目描述 :
Better error logs for unhandled errors in promises
高级语言: JavaScript
项目地址: git://github.com/papb/better-promise-error-log.git
创建时间: 2018-02-09T14:03:14Z
项目社区:https://github.com/papb/better-promise-error-log

开源协议:MIT License

下载


better-promise-error-log

npm package

NPM version
Minzipped size
License
NPM downloads
Dependency Status
Dev Dependency Status
Open Issues
Closed Issues
contributions welcome
jsDelivr hits

Better error logs for unhandled errors in promises.

Tested with native promises and Bluebird promises.

This module uses the sibling module, jsonify-error, to prepare the error for logging.

Installation

In Browsers

For browsers, simply include one of the dists in your entry point. The dists are available in jsDelivr:

  1. <script src="https://cdn.jsdelivr.net/npm/better-promise-error-log@1.5.2/dist/better-promise-error-log.min.js" integrity="sha384-cyUN0kjnDSNpcYRqS2sNJ6tDyzBAqtW/SwCtK9vDoGYREaHRXrdTsZVK7uwzd2Wl" crossorigin="anonymous"></script>

They are also available as GitHub release assets (since 1.5.1). The following formats are available (with source maps):

  • better-promise-error-log.js
  • better-promise-error-log.min.js (minified)
  • better-promise-error-log.es5.js (ES5 compatible)
  • better-promise-error-log.es5.min.js (ES5 compatible, minified)

In Node

  1. npm install --save better-promise-error-log

Add the following line to the beginning of your entry point:

  1. require("better-promise-error-log");

And then automatically your whole program will have better error logs for unhandled errors in promises.

Example result (in node)

  1. // Uncomment line below to see the difference
  2. // require("better-promise-error-log");
  3. Promise.resolve().then(() => {
  4. var err = new TypeError("My message");
  5. err.someField = { something: "whoops" };
  6. TypeError.prototype.test = "oops!"; // Just to show that it navigates the prototype chain
  7. throw err;
  8. }).then(() => {
  9. console.log("This does not execute.");
  10. });

Without require("better-promise-error-log"):

In node, without better-promise-error-log

With require("better-promise-error-log"), you’ll get something similar to:

In node, with better-promise-error-log

Note: the whole error formatting is done by the sibling module, jsonify-error.

Example result (in browser)

  1. Promise.resolve().then(() => {
  2. var err = new TypeError("My message");
  3. err.someField = { something: "whoops" };
  4. TypeError.prototype.test = "oops!"; // Just to show that it navigates the prototype chain
  5. throw err;
  6. }).then(() => {
  7. console.log("This does not execute.");
  8. });

Without better-promise-error-log:

In browser, without better-promise-error-log

With better-promise-error-log, you’ll get something similar to:

In browser, with better-promise-error-log

Note: the whole error formatting is done by the sibling module, jsonify-error.

Contributing

Any contribution is very welcome. Feel free to open an issue about anything: questions, suggestions, feature requests, bugs, improvements, mistakes, whatever. I will be always looking.

Changelog

The changelog is available in CHANGELOG.md.

License

MIT (c) Pedro Augusto de Paula Barbosa