Refactor error handling and startup logic in index.js

This commit is contained in:
Christopher Cookman 2024-05-08 08:33:32 -06:00
parent 2db900e154
commit f0b45c190b
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -85,17 +85,20 @@ const xmpp = client({
//debug(xmpp, true);
xmpp.on("error", (err) => {
console.log("ERROR")
console.error(err);
console.log(`ERR: ${err}`);
setTimeout(() => {
xmpp.stop().then(() => {
start();
});
}, 5000);
});
xmpp.on("offline", () => {
console.log("offline");
setTimeout(() => {
xmpp.stop().then(() => {
start();
});
}, 5000);
});
@ -244,14 +247,12 @@ xmpp.on("online", async (address) => {
});
const start = () => {
xmpp.stop().then(() => {
xmpp.start().catch((err) => {
console.error(`start failed, ${err}\nGonna try again in 5 seconds...`);
setTimeout(() => {
start();
}, 5000);
});
}); // Do this just in case
}
// END XMPP
@ -511,5 +512,14 @@ discord.on("interactionCreate", async (interaction) => {
}
});
process.on("unhandledRejection", (error) => {
console.error("Unhandled promise rejection:", error);
});
process.on("uncaughtException", (error) => {
console.error("Uncaught exception:", error);
});
// Login to discord
discord.login(config.discord.token);