fix error handling for connections

v2
Kit Kasune 2 years ago
parent 3182903c77
commit 00af710ebd
  1. 1
      bot.js
  2. 8
      src/db/connect.js
  3. 8
      src/handle/startup/run/login.js

@ -18,6 +18,7 @@ const startBot = async () => {
client.config.randResp = randresp;
require('./src/util/misc/setutils')(client); // add some basic swiss army knife utils
const loggers = log(client);
Object.keys(loggers).forEach(logger => client[logger] = loggers[logger]);

@ -7,13 +7,15 @@ const ora = require('../util/log/ora');
module.exports = async client => {
const auth = client.auth;
const t = Date.now();
client.misc.dbconnected = false;
client.misc.dbconnected = true;
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."),
mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.3jpp4.mongodb.net/test`, {
useFindAndModify: false, useNewUrlParser: true, dbName: auth.database.name, useUnifiedTopology: true, useCreateIndex: true
})
).catch((e) => client.error("Failed to connect to mongoose!! Error below.", 0, true, true, e))
.then(() => {client.misc.dbconnected = true;});
).catch((e) => {
client.error("Failed to connect to mongoose!! Error below.", 0, 0, true, e);
client.misc.dbconnected = false;
});
if (!client.misc.dbconnected) {
client.warn("Database not connected, considering runtime to be unusable and exiting.", 0, true, true);
throw new Error();

@ -5,12 +5,14 @@ const ora = require('../../../util/log/ora');
module.exports = async (client) => {
const t = Date.now();
client.misc = {};
client.misc.dscconnected = false;
client.misc.dscconnected = true;
await ora(`Waking up Natsuki... ${chalk.blueBright.bold.underline("(Connecting to Discord...)")}`,
client.login(client.auth.token)
).catch((e) => client.error("Failed to connect to Discord!! Error below.", 0, true, true, e))
.then(() => {client.misc.dscconnected = true;});
).catch((e) => {
client.error("Failed to connect to Discord!! Error below.", 0, 0, true, e);
client.misc.dscconnected = false;
});
if (!client.misc.dscconnected) {
client.warn("Discord not connected, considering runtime to be unusable and exiting.", 0, true, true);
throw new Error();

Loading…
Cancel
Save