Refactor error handling and startup logic in index.js
This commit is contained in:
parent
2db900e154
commit
f0b45c190b
18
index.js
18
index.js
|
@ -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);
|
Loading…
Reference in a new issue