fix/handle failed mongo connection

This commit is contained in:
SowinskiBraeden committed 2024-11-17 09:13:02 -08:00
1 parent a3a0e978f9
commit 5fb88a0a09
2 files changed
+7 -4

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "dayzr-bot", "name": "dayzr-bot",
"version": "13.3.13", "version": "13.3.14",
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
"main": "index.js", "main": "index.js",
"nodemonConfig": { "nodemonConfig": {
+6 -3
View File
@@ -384,8 +384,10 @@ class DayzRBot extends Client {
databaselogs.attempts = 0; // reset attempts databaselogs.attempts = 0; // reset attempts
this.databaseConnected = true; this.databaseConnected = true;
} catch (err) { } catch (err) {
databaselogs.attempts++; databaselogs.attempts++;
let db = (mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]).endsWith("/") ? mongoURI.slice(0, -1) : mongoURI; databaselogs.connected = false;
let db = mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1];
db = db.includes("/") ? db.split("/")[0] : db;
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`); this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
failed = true; failed = true;
} }
@@ -399,7 +401,8 @@ class DayzRBot extends Client {
async initialize() { async initialize() {
// Wait for MongoDB to connect // Wait for MongoDB to connect
await this.connectMongo(this.config.mongoURI, this.config.dbo); await this.connectMongo(this.config.mongoURI, this.config.dbo);
if (!this.databaseConnected) return;
let guilds = await this.dbo.collection("guilds").find({}).toArray(); let guilds = await this.dbo.collection("guilds").find({}).toArray();
/* /*