From 5365e777fe5964b61ff854bfb95c6a328b92dcb4 Mon Sep 17 00:00:00 2001 From: dayflywu Date: Mon, 17 Oct 2022 23:21:59 +0800 Subject: [PATCH 1/2] fix: Fix for the "too many requests" issue --- src/request.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/request.js b/src/request.js index 6eac7ef..b8d5776 100644 --- a/src/request.js +++ b/src/request.js @@ -45,11 +45,12 @@ export default function request({method, host, path, qs, agent}) { }); res.on('end', () => { - if (res.statusCode === 429 && res.headers['set-cookie']) { + if (res.statusCode === 429) { // Fix for the "too many requests" issue // Look for the set-cookie header and re-request - cookieVal = res.headers['set-cookie'][0].split(';')[0]; - options.headers = {'cookie': cookieVal}; + cookieVal = res.headers['set-cookie'] ? + res.headers['set-cookie'][0].split(';')[0] : ''; + options.headers = cookieVal ? {'cookie': cookieVal} : {}; rereq(options, function(err, response) { if (err) return reject(err); resolve(response); From 1af08dc916a27be75d045c7028c0e3eaf7eb9b4c Mon Sep 17 00:00:00 2001 From: dayflywu Date: Fri, 21 Oct 2022 14:22:41 +0800 Subject: [PATCH 2/2] fix: delete agent param from querystring --- src/utilities.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utilities.js b/src/utilities.js index 6f2152f..308d402 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -162,6 +162,10 @@ export function parseResults(results) { * @return {Array} Returns an array of comparisonItems */ export function formatComparisonItems(obj) { + // fix the querystring has the agent param from obj + obj = Object.assign({}, obj); + delete obj.agent; + const isMultiRegion = obj.geo && Array.isArray(obj.geo); let isMultiKeyword = Array.isArray(obj.keyword);