Skip to content

Instantly share code, notes, and snippets.

@ViniciusResende
Created May 26, 2022 18:06
Show Gist options
  • Select an option

  • Save ViniciusResende/3135fa9cb15917c383868983ed83ed98 to your computer and use it in GitHub Desktop.

Select an option

Save ViniciusResende/3135fa9cb15917c383868983ed83ed98 to your computer and use it in GitHub Desktop.
*verifyBrandsURLsActiveness(brandsURLs) {
const brandsArray = ['americanas', 'submarino', 'shoptime']
return yield Object.values(brandsURLs).reduce(function*(acc, urlObject, idx) {
let urlDoesExists;
const turboApiUrl = `${turboApiConfig[brandsArray[idx]]}/${urlObject.path}`
try {
const { statusCode } = yield rp({
url: turboApiUrl,
resolveWithFullResponse: true,
timeout: 5000
})
logger.info("Turbo Request resolved with status code ", statusCode)
urlDoesExists = statusCode === 200
} catch(err) {
logger.info("Turbo Request failed with error ", err)
urlDoesExists = false
}
return {
...(yield acc),
[brandsArray[idx]]: {
url: urlObject.url,
active: urlDoesExists
}
}
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment