'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); } } }