Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const util = require('util');
  3. const onExit = require('signal-exit');
  4. const currentlyUnhandled = require('currently-unhandled');
  5. let installed = false;
  6. const loudRejection = (log = console.error) => {
  7. if (installed) {
  8. return;
  9. }
  10. installed = true;
  11. const listUnhandled = currentlyUnhandled();
  12. onExit(() => {
  13. const unhandledRejections = listUnhandled();
  14. if (unhandledRejections.length > 0) {
  15. for (const unhandledRejection of unhandledRejections) {
  16. let error = unhandledRejection.reason;
  17. if (!(error instanceof Error)) {
  18. error = new Error(`Promise rejected with value: ${util.inspect(error)}`);
  19. }
  20. log(error.stack);
  21. }
  22. process.exitCode = 1;
  23. }
  24. });
  25. };
  26. module.exports = loudRejection;
  27. // TODO: remove this in the next major version
  28. module.exports.default = loudRejection;