1
0
mirror of https://github.com/thangisme/notes.git synced 2024-10-31 23:27:32 -04:00
notes/node_modules/loud-rejection/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

37 lines
682 B
JavaScript

'use strict';
var util = require('util');
var onExit = require('signal-exit');
var currentlyUnhandled = require('currently-unhandled');
var installed = false;
module.exports = function (log) {
if (installed) {
return;
}
installed = true;
log = log || console.error;
var listUnhandled = currentlyUnhandled();
onExit(function () {
var unhandledRejections = listUnhandled();
if (unhandledRejections.length > 0) {
unhandledRejections.forEach(function (x) {
var err = x.reason;
if (!(err instanceof Error)) {
err = new Error('Promise rejected with value: ' + util.inspect(err));
}
log(err.stack);
});
process.exitCode = 1;
}
});
};