Skip to content

Commit 31bee73

Browse files
committed
feat(app): add mongodb error handling to quit app if unable to connect with mongodb server for some
reason when the app will be started with grunt serve, if configured to run with mongodb and the service will not be available, then the app will initialize anyway but mostly this isnt desired and no handling or debug information of why the app has no connection to a mongodb server will be provided
1 parent 49a3a14 commit 31bee73

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: app/templates/server/app.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ var config = require('./config/environment');
1313
<% if (filters.mongoose) { %>
1414
// Connect to database
1515
mongoose.connect(config.mongo.uri, config.mongo.options);
16-
16+
mongoose.connection.on('error', function(err) {
17+
console.error('MongoDB connection error: ' + err);
18+
process.exit(-1);
19+
}
20+
);
1721
// Populate DB with sample data
1822
if(config.seedDB) { require('./config/seed'); }
1923

0 commit comments

Comments
 (0)