diff --git a/app/helpers/fetchWrapper.js b/app/helpers/fetchWrapper.js index a6fd4b4..8c0c457 100644 --- a/app/helpers/fetchWrapper.js +++ b/app/helpers/fetchWrapper.js @@ -6,14 +6,8 @@ const { SCRAPER_API_BASE_URL } = require("../config/appConfig"); -const async timeout = (method, ms) => { - console.error("Waiting for ", ms); - return new Promise(resolve => { - setTimeout(() => { - await method(); - resolve(); - }, ms); - }); +const timeout = (ms) => { + return new Promise(resolve => setTimeout(resolve, ms)); } const fetch = async (url, options = {}) => { @@ -32,7 +26,8 @@ const fetch = async (url, options = {}) => { ? `${SCRAPER_API_BASE_URL}?api_key=${SCRAPER_API_KEY}&url=${urlToFetchThroughAPI}` : url; const randomPauseMS = Math.floor(Math.random() * Math.floor(1500)) + 500; - return timeout(() => { nodeFetch(urlAdaptedForScraping, newOptions); }, randomPauseMS); + await timeout(randomPauseMS); + return nodeFetch(urlAdaptedForScraping, newOptions); }; module.exports = fetch;