diff --git a/index.js b/index.js index 9a0d509..72356bb 100644 --- a/index.js +++ b/index.js @@ -5,13 +5,17 @@ const logger = require('./modules/logger')('request-promise-retry'); class rpRetry { static _rpRetry(options) { - logger.info(`calling ${options.uri} with retry ${options.retry}`); + if(options.verbose_logging) { + logger.info(`calling ${options.uri} with retry ${options.retry}`); + } const tries = options.retry || 1; delete options.retry; const fetchDataWithRetry = tryCount => { return requestPromise(options) .then(result => { - logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + if(options.verbose_logging) { + logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + } return Promise.resolve(result); }) .catch(err => { @@ -27,10 +31,14 @@ class rpRetry { } static _rp(options) { - logger.info(`calling ${options.uri} without retries`); + if(options.verbose_logging) { + logger.info(`calling ${options.uri} without retries`); + } return requestPromise(options) .then(result => { - logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + if(options.verbose_logging) { + logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + } return Promise.resolve(result); }) .catch(err => { @@ -57,4 +65,4 @@ class rpRetry { } } -module.exports = rpRetry.rp; \ No newline at end of file +module.exports = rpRetry.rp; diff --git a/test/index.test.js b/test/index.test.js index 68d8cd7..c18eb35 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -15,11 +15,22 @@ const optionsWithRetry = { method: 'GET', retry: 4 }; +const optionsWithRetryAndLogging = { + uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', + method: 'GET', + verboseLogging: true, + retry: 4 +}; const optionsWithoutRetry = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET' }; +const optionsWithoutRetryWithLogging = { + uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', + method: 'GET', + verboseLogging: true +}; const optionsBadRetry1 = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET', @@ -43,6 +54,12 @@ describe('request-promise-retry', function () { expect(data.error).equal(undefined); }); }); + it('should pass, with retry options, with verbose logging', () => { + return rp(optionsWithRetryAndLogging) + .then(data => { + expect(data.error).equal(undefined); + }); + }); it('fail and retry 3 times', () => { return rp(optionsWithRetryFail) .catch(err => { @@ -55,6 +72,12 @@ describe('request-promise-retry', function () { expect(data.error).equal(undefined); }); }); + it('should pass, without retry options, with logging', () => { + return rp(optionsWithoutRetryWithLogging) + .then(data => { + expect(data.error).equal(undefined); + }); + }); it('should fail, without retry options', () => { return rp(optionsWithoutRetryFail) .catch(err => {