corde
Version:
A simple library for Discord bot tests
47 lines (36 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.initErrorHandlers = void 0;
const runtime_1 = require("./common/runtime");
const testCollector_1 = require("./common/testCollector");
const exit_1 = require("./exit");
function initErrorHandlers() {
process.on("uncaughtException", async (err) => {
await printErrorAndExit(err);
});
process.on("unhandledRejection", async (err) => {
await printErrorAndExit(err);
});
process.on("uncaughtExceptionMonitor", async (err) => {
await printErrorAndExit(err);
});
}
exports.initErrorHandlers = initErrorHandlers;
async function printErrorAndExit(error) {
if (error instanceof Error) {
console.error(error.message);
} else {
console.error(error);
}
if (runtime_1.runtime.isBotLoggedIn()) {
runtime_1.runtime.logoffBot();
}
if (testCollector_1.testCollector.afterAllFunctions) {
await testCollector_1.testCollector.afterAllFunctions.executeAsync();
}
if (process.env.ENV !== "TEST") {
(0, exit_1.exit)(1);
}
}