feat: add error handling for db conn

This commit is contained in:
Rohit
2025-03-25 21:44:28 +05:30
parent cee88e3b62
commit 198aa1f60e

View File

@@ -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