From 60e90313250a3f40d855247180fdbe57868a3a52 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 May 2024 01:51:50 -0600 Subject: [PATCH] - Change how we handle disconnects/startup errors --- index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 7ef376a..330d59b 100644 --- a/index.js +++ b/index.js @@ -470,26 +470,23 @@ xmpp.on("online", async (address) => { xmpp.on("close", () => { console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`); - setTimeout(() => { - xmpp.stop().then(() => { - start(); - }); - }, 5000); + xmpp.stop().then(() => { + start(); + }) }) const start = () => { + startup = true; xmpp.start().catch((err) => { errCount++; if (errCount >= 5) { console.log(`${colors.red("[ERROR]")} XMPP failed to start after 5 attempts, exiting...`); process.exit(1); } - console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}. Trying again in 5 seconds...`); - xmpp.close(); - xmpp.disconnect(); - setTimeout(() => { + console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`); + xmpp.stop().then(() => { start(); - }, 5000); + }) }); }