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.

32 lines
632 B
JavaScript

'use strict';
const unhandledRejection = require("unhandled-rejection");
module.exports = function createUnhandledErrorHandler(handler, options = {}) {
function handleError(error, context) {
handler(error, context);
if (options.doNotCrash !== true) {
process.exit(1);
}
}
let rejectionEmitter = unhandledRejection();
rejectionEmitter.on("unhandledRejection", (error, promise) => {
handleError(error, {
promise: promise
});
});
process.on("uncaughtException", (error) => {
handleError(error, {});
});
return {
report: function reportError(error, context) {
handleError(error, context);
}
}
}