diff --git a/lib/connection.js b/lib/connection.js index 2d1dc0f71c3..0c7e138238f 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -328,6 +328,8 @@ Connection.prototype.open = function() { }); }); + // Monkey-patch `.then()` so if the promise is handled, we don't emit an + // `error` event. var _then = promise.then; promise.then = function(resolve, reject) { promise.$hasHandler = true; @@ -584,6 +586,15 @@ Connection.prototype.openSet = function(uris, database, options, callback) { resolve(); }); }); + + // Monkey-patch `.then()` so if the promise is handled, we don't emit an + // `error` event. + var _then = promise.then; + promise.then = function(resolve, reject) { + promise.$hasHandler = true; + return _then.call(promise, resolve, reject); + }; + return promise; };