@@ -337,6 +337,7 @@ Connection.prototype.openUri = function(uri, options, callback) {
337
337
const promise = new Promise ( ( resolve , reject ) => {
338
338
parser ( uri , options , ( error , parsed ) => {
339
339
if ( error ) {
340
+ this . readyState = STATES . disconnected ;
340
341
if ( _this . listeners ( 'error' ) . length > 0 ) {
341
342
_this . emit ( 'error' , error ) ;
342
343
}
@@ -357,6 +358,7 @@ Connection.prototype.openUri = function(uri, options, callback) {
357
358
358
359
mongodb . MongoClient . connect ( uri , options , function ( error , client ) {
359
360
if ( error ) {
361
+ _this . readyState = STATES . disconnected ;
360
362
if ( _this . listeners ( 'error' ) . length > 0 ) {
361
363
_this . emit ( 'error' , error ) ;
362
364
}
@@ -366,13 +368,6 @@ Connection.prototype.openUri = function(uri, options, callback) {
366
368
_this . db = db ;
367
369
_this . client = client ;
368
370
369
- if ( error ) {
370
- _this . readyState = STATES . disconnected ;
371
- if ( _this . listeners ( 'error' ) . length ) {
372
- _this . emit ( 'error' , error ) ;
373
- }
374
- return reject ( error ) ;
375
- }
376
371
// Backwards compat for mongoose 4.x
377
372
db . on ( 'reconnect' , function ( ) {
378
373
_this . readyState = STATES . connected ;
0 commit comments