Bug Description
Description
The database connection logic catches connection errors but does not propagate or handle them appropriately. As a result, the server can start successfully even when MongoDB is unavailable.
Acceptance Criteria
Steps to Reproduce
- Application starts in an unhealthy state.
- Database-dependent requests fail at runtime.
- Operational issues become harder to diagnose.
- Monitoring systems may incorrectly report the service as healthy.
Expected Behavior
The application should fail fast when a database connection cannot be established.
Suggested Solution
Terminate the process when the database connection fails.
catch (error) {
console.error("Database connection failed:", error);
process.exit(1);
}
Current Behavior
const connectdb = async () => {
try {
await mongoose.connect(process.env.MONGODB_URL);
console.log("DB connected");
} catch (_error) {
console.log("DB error");
}
};
If the database connection fails, the application continues running and accepts requests despite being unable to access required data.
Environment
MacOS, Safari, Windows, Linux
Logs/Screenshots
No response
Bug Description
Description
The database connection logic catches connection errors but does not propagate or handle them appropriately. As a result, the server can start successfully even when MongoDB is unavailable.
Acceptance Criteria
Steps to Reproduce
Expected Behavior
The application should fail fast when a database connection cannot be established.
Suggested Solution
Terminate the process when the database connection fails.
Current Behavior
If the database connection fails, the application continues running and accepts requests despite being unable to access required data.
Environment
MacOS, Safari, Windows, Linux
Logs/Screenshots
No response