From f692118d517cc72d74975d8335668e2b1878c8fe Mon Sep 17 00:00:00 2001 From: Ravi Teja Gannavarapu Date: Sat, 6 Oct 2018 02:43:10 +0530 Subject: [PATCH] Catch connection initialization errors This catches database connection initialization errors. Fixes https://github.com/feathersjs/feathers/issues/1037 --- .../generators/connection/templates/mongodb.js | 3 +++ .../generators/connection/templates/rethinkdb.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/generator-feathers/generators/connection/templates/mongodb.js b/packages/generator-feathers/generators/connection/templates/mongodb.js index 0f96be6176..44e159ed47 100644 --- a/packages/generator-feathers/generators/connection/templates/mongodb.js +++ b/packages/generator-feathers/generators/connection/templates/mongodb.js @@ -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'); @@ -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); diff --git a/packages/generator-feathers/generators/connection/templates/rethinkdb.js b/packages/generator-feathers/generators/connection/templates/rethinkdb.js index 5dd96646fc..721cfd6380 100644 --- a/packages/generator-feathers/generators/connection/templates/rethinkdb.js +++ b/packages/generator-feathers/generators/connection/templates/rethinkdb.js @@ -1,4 +1,5 @@ const rethinkdbdash = require('rethinkdbdash'); +const logger = require('./logger'); module.exports = function (app) { const config = app.get('rethinkdb'); @@ -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); + }); } });