From f5d790b26451b923a8edf21574d59215c19d78ef Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 30 Dec 2015 11:40:56 +0100 Subject: [PATCH] Do not automatically retry on connection errors! --- packages/xo-lib/xo.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/xo-lib/xo.js b/packages/xo-lib/xo.js index 6f92ed583..336865d77 100644 --- a/packages/xo-lib/xo.js +++ b/packages/xo-lib/xo.js @@ -170,7 +170,7 @@ function Xo (opts) { this._connect() } -Xo.prototype.call = function (method, params) { +Xo.prototype.call = function (method, params, retryOnConnectionError) { // Prevent session.*() from being because it may interfere // with this class session management. if (startsWith(method, 'session.')) { @@ -179,11 +179,19 @@ Xo.prototype.call = function (method, params) { ) } - return this._session.bind(this).then(function () { - return this._api.call(method, params) - }).catch(ConnectionError, SessionError, function () { - // Automatically requeue this call. - return this.call(method, params) + var this_ = this + return this._session.then(function () { + return this_._api.call(method, params) + }).catch(function (error) { + if ( + error instanceof SessionError || + retryOnConnectionError && error instanceof ConnectionError + ) { + // Automatically requeue this call. + return this_.call(method, params) + } + + throw error }) }