Skip to content

Commit

Permalink
Catch connection initialization errors
Browse files Browse the repository at this point in the history
This catches database connection initialization errors.

Fixes #1037
  • Loading branch information
IamRaviTejaG committed Oct 5, 2018
1 parent 815ffe6 commit f692118
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const parse = require('mongodb-core').parseConnectionString;
const MongoClient = require('mongodb').MongoClient;
const logger = require('./logger');

module.exports = function (app) {
const config = app.get('mongodb');
Expand All @@ -11,6 +12,8 @@ module.exports = function (app) {

const dbName = parse(config, () => {});
return client.db(dbName);
}).catch(error => {
logger.error(error);
});

app.set('mongoClient', promise);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const rethinkdbdash = require('rethinkdbdash');
const logger = require('./logger');

module.exports = function (app) {
const config = app.get('rethinkdb');
Expand All @@ -16,7 +17,11 @@ module.exports = function (app) {
const service = app.service(path);

if (typeof service.init === 'function') {
promise = promise.then(() => service.init());
promise = promise.then(() => {
service.init();
}).catch(error => {
logger.error(error);
});
}
});

Expand Down

0 comments on commit f692118

Please sign in to comment.