index.js 500 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const util = require('util');
  3. let installed = false;
  4. const hardRejection = (log = console.error) => {
  5. if (installed) {
  6. return;
  7. }
  8. installed = true;
  9. process.on('unhandledRejection', error => {
  10. if (!(error instanceof Error)) {
  11. error = new Error(`Promise rejected with value: ${util.inspect(error)}`);
  12. }
  13. log(error.stack);
  14. process.exit(1);
  15. });
  16. };
  17. module.exports = hardRejection;
  18. // TODO: Remove this for the next major release
  19. module.exports.default = hardRejection;