From 198aa1f60e08f5b437cfb3e3fc0d8cc1afc77f2f Mon Sep 17 00:00:00 2001 From: Rohit Date: Tue, 25 Mar 2025 21:44:28 +0530 Subject: [PATCH] feat: add error handling for db conn --- server/src/db/models/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/src/db/models/index.js b/server/src/db/models/index.js index dc97bee9..1f044a8d 100644 --- a/server/src/db/models/index.js +++ b/server/src/db/models/index.js @@ -11,9 +11,21 @@ const db = {}; let sequelize; if (config.use_env_variable) { - sequelize = new Sequelize(process.env[config.use_env_variable], config); + try { + sequelize = new Sequelize(process.env[config.use_env_variable], config); + console.log(`Connected to database using ${config.use_env_variable}`); + } catch (error) { + console.error('Unable to connect to the database using environment variable:', error); + process.exit(1); + } } else { - sequelize = new Sequelize(config.database, config.username, config.password, config); + try { + sequelize = new Sequelize(config.database, config.username, config.password, config); + console.log(`Connected to database: ${config.database}`); + } catch (error) { + console.error('Unable to connect to the database:', error); + process.exit(1); + } } fs