forked from ChrisChrome/weather-bot
- Change how we handle disconnects/startup errors
This commit is contained in:
parent
b2615c7b21
commit
60e9031325
13
index.js
13
index.js
|
@ -470,26 +470,23 @@ xmpp.on("online", async (address) => {
|
||||||
|
|
||||||
xmpp.on("close", () => {
|
xmpp.on("close", () => {
|
||||||
console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`);
|
console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`);
|
||||||
setTimeout(() => {
|
|
||||||
xmpp.stop().then(() => {
|
xmpp.stop().then(() => {
|
||||||
start();
|
start();
|
||||||
});
|
})
|
||||||
}, 5000);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const start = () => {
|
const start = () => {
|
||||||
|
startup = true;
|
||||||
xmpp.start().catch((err) => {
|
xmpp.start().catch((err) => {
|
||||||
errCount++;
|
errCount++;
|
||||||
if (errCount >= 5) {
|
if (errCount >= 5) {
|
||||||
console.log(`${colors.red("[ERROR]")} XMPP failed to start after 5 attempts, exiting...`);
|
console.log(`${colors.red("[ERROR]")} XMPP failed to start after 5 attempts, exiting...`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}. Trying again in 5 seconds...`);
|
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
|
||||||
xmpp.close();
|
xmpp.stop().then(() => {
|
||||||
xmpp.disconnect();
|
|
||||||
setTimeout(() => {
|
|
||||||
start();
|
start();
|
||||||
}, 5000);
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue