-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
38 lines (28 loc) · 829 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const util = require('util');
const onExit = require('signal-exit');
const currentlyUnhandled = require('currently-unhandled');
let installed = false;
const loudRejection = (log = console.error) => {
if (installed) {
return;
}
installed = true;
const listUnhandled = currentlyUnhandled();
onExit(() => {
const unhandledRejections = listUnhandled();
if (unhandledRejections.length > 0) {
for (const unhandledRejection of unhandledRejections) {
let error = unhandledRejection.reason;
if (!(error instanceof Error)) {
error = new Error(`Promise rejected with value: ${util.inspect(error)}`);
}
log(error.stack);
}
process.exitCode = 1;
}
});
};
module.exports = loudRejection;
// TODO: remove this in the next major version
module.exports.default = loudRejection;