diff --git a/lib/datasource.js b/lib/datasource.js index 2d7215fb..027eb866 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -220,7 +220,7 @@ DataSource.prototype.setup = function(name, settings) { } if (connector) { - var postInit = function postInit() { + var postInit = function postInit(err, result) { this._setupConnector(); // we have an connector now? @@ -228,8 +228,10 @@ DataSource.prototype.setup = function(name, settings) { throw new Error('Connector is not defined correctly: it should create `connector` member of dataSource'); } - this.connected = true; - this.emit('connected'); + this.connected = !err; // Connected now + if(this.connected) { + this.emit('connected'); + } }.bind(this);