Skip to content

Commit

Permalink
fix: Catch connection initialization errors (#1043)
Browse files Browse the repository at this point in the history
This catches database connection initialization errors.

Fixes #1037
  • Loading branch information
IamRaviTejaG-zz authored and daffl committed Oct 6, 2018
1 parent 0275722 commit 4f9acd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
@@ -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
@@ -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 4f9acd6

Please sign in to comment.