From d5da9caaa98773631378c0ddffd78fb0b85c9d73 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 12 May 2017 15:57:26 -0600 Subject: [PATCH] fix(connection): set $hasHandler on promises returned from openSet() Re: #5229 --- lib/connection.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; };