diff --git a/lib/connection/statement.js b/lib/connection/statement.js index 7797d6505..32af85f09 100644 --- a/lib/connection/statement.js +++ b/lib/connection/statement.js @@ -1570,12 +1570,14 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry) // retry, update the url if ((numRetries > 0) && appendQueryParamOnRetry) { - let retryUrl; - retryUrl = Util.url.appendParam(urlOrig, 'retryCount', numRetries); - if(connectionConfig.getIncludeRetryContext){ - retryUrl = Util.url.appendParam(retryUrl, 'retryReason', lastStatusCodeForRetry); + const retryOption = { + url: urlOrig, + retryCount: numRetries, + retryReason: lastStatusCodeForRetry, + includeRetryContext: connectionConfig.getIncludeRetryContext() } - options.url = retryUrl; + + options.url = Util.url.appendRetryParam(retryOption); } sf.request(options); diff --git a/lib/util.js b/lib/util.js index 0d607f9e6..3ebb3bd12 100644 --- a/lib/util.js +++ b/lib/util.js @@ -344,6 +344,14 @@ exports.url = } return url; + }, + + appendRetryParam: function (option) { + let retryUrl = this.appendParam(option.url, 'retryCount', option.retryCount); + if (option.includeRetryContext) { + retryUrl = this.appendParam(retryUrl, 'retryReason', option.retryReason); + } + return retryUrl; } }; diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 485938297..d0852ae1c 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -488,6 +488,37 @@ describe('Util', function () } }); + it('Util.url.appendRetryParam()', function () { + let url; + const testCases = + [ + { + option: { + url: 'http://www.something.snowflakecomputing.com', + retryCount: 3, + retryReason: 429, + includeRetryContext: true, + }, + result: 'http://www.something.snowflakecomputing.com?retryCount=3&retryReason=429' + }, + { + option: { + url: 'http://www.something.snowflakecomputing.com', + retryCount: 3, + retryReason: 429, + includeRetryContext: false, + }, + result: 'http://www.something.snowflakecomputing.com?retryCount=3' + } + ]; + + for (let i = 0; i < testCases.length; i++) { + testCase = testCases[i]; + url = Util.url.appendRetryParam(testCase.option); + assert.strictEqual(url, testCase.result); + } + }) + it('Util.apply()', function () { assert.strictEqual(Util.apply(null, null), null);