You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
682 B
JavaScript
37 lines
682 B
JavaScript
6 years ago
|
'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;
|
||
|
}
|
||
|
});
|
||
|
};
|