Skip to content

Commit

Permalink
Added improved error message when mongo connection fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Dec 19, 2014
1 parent bd3fba3 commit ca098e1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/adapter.js
Expand Up @@ -8,6 +8,8 @@ var Collection = require('./collection');
var Errors = require('waterline-errors').adapter;
var ObjectId = require('mongodb').ObjectID;
var _runJoins = require('waterline-cursor');
var util = require('util');


module.exports = (function() {

Expand Down Expand Up @@ -88,8 +90,16 @@ module.exports = (function() {
};

// Create a new active connection
new Connection(connection, function(err, db) {
if(err) return cb(err);
new Connection(connection, function(_err, db) {

if(_err) {
return cb((function _createError(){
var msg = util.format('Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?\n Error details:\n%s', util.inspect(_err, false, null));
var err = new Error(msg);
err.originalError = _err;
return err;
})());
}
connections[connection.identity].connection = db;

// Build up a registry of collections
Expand Down

0 comments on commit ca098e1

Please sign in to comment.