From 8460f037a8f6db49685e26e755956873767c67cd Mon Sep 17 00:00:00 2001 From: Simon Liang Date: Sat, 16 Dec 2017 15:44:41 +0800 Subject: [PATCH 1/3] Updated README on sample Date Making sure it conforms with the correct signature --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e3ede8..c67a4b4 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ Usage: mws.Orders.ListOrders({ MarketplaceId: 'lel', MaxResultsPerPage: 10, - CreatedAfter: new Date(1,1,2015), - CreatedBefore: new Date(1,2,2015) + CreatedAfter: new Date(2015, 1, 1), + CreatedBefore: new Date(2015, 1, 2) }) .then(({ result, metadata }) => { // result From 9aed09f503b39ae1285b50764669d00c330d195c Mon Sep 17 00:00:00 2001 From: Simon Liang Date: Sun, 1 Apr 2018 15:47:17 +0800 Subject: [PATCH 2/3] fixes travis ci error --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fa057c3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "4" + - "5" + - "6" + - "7" + - "8" + - "9" +sudo: false From 49d9eb4e27f0ad3968034129c7f22ad51bd9daae Mon Sep 17 00:00:00 2001 From: Simon Liang Date: Sun, 1 Apr 2018 15:54:42 +0800 Subject: [PATCH 3/3] added a retry for 500 internal service error --- lib/client.js | 56 ++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/lib/client.js b/lib/client.js index 5f53749..d4180a7 100644 --- a/lib/client.js +++ b/lib/client.js @@ -123,6 +123,25 @@ class AmazonMwsClient { * @return Promise */ call(req, q, meta) { + + const doRetry = (err) => { + if (!meta.retry) { + throw err; + } + + const attempt = meta.attempt + 1; + + if (attempt > meta.max_attempts) { + throw err; + } + + // simple exponential backoff for dealing with throttling + const backoffDuration = Math.min(100 * Math.pow(2, attempt), meta.max_backoff); + + return Promise.delay(backoffDuration) + .then(() => this.call(req, q, _.assign({}, meta, { attempt }))); + }; + return this.request(req, q, meta).then((response) => { const body = response.body; @@ -166,40 +185,9 @@ class AmazonMwsClient { metadata: _.concat(metadata, nextData.metadata) })); }) - .catch({ code: 'RequestThrottled' }, (err) => { - if (!meta.retry) { - throw err; - } - - const attempt = meta.attempt + 1; - - if (attempt > meta.max_attempts) { - throw err; - } - - // simple exponential backoff for dealing with throttling - const backoffDuration = Math.min(100 * Math.pow(2, attempt), meta.max_backoff); - - return Promise.delay(backoffDuration) - .then(() => this.call(req, q, _.assign({}, meta, { attempt }))); - }) - .catch({ code: 'QuotaExceeded' }, (err) => { - if (!meta.retry) { - throw err; - } - - const attempt = meta.attempt + 1; - - if (attempt > meta.max_attempts) { - throw err; - } - - // simple exponential backoff for dealing with throttling - const backoffDuration = Math.min(100 * Math.pow(2, attempt), meta.max_backoff); - - return Promise.delay(backoffDuration) - .then(() => this.call(req, q, _.assign({}, meta, { attempt }))); - }); + .catch({ code: 'InternalError' }, doRetry) + .catch({ code: 'RequestThrottled' }, doRetry) + .catch({ code: 'QuotaExceeded' }, doRetry); }); }