Skip to content

Instantly share code, notes, and snippets.

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

  • Save ViniciusResende/21c55b27eeceedb709b65e44d59bce41 to your computer and use it in GitHub Desktop.

Select an option

Save ViniciusResende/21c55b27eeceedb709b65e44d59bce41 to your computer and use it in GitHub Desktop.
*verifyBrandsURLsActiveness(brandsURLs) {
function* getTurboRequestStatusCode(brand) {
try {
const { statusCode } = yield rp({
url: `${turboApiConfig[brand]}/${brandsURLs[brand].path}`,
resolveWithFullResponse: true,
timeout: 5000
})
return statusCode;
} catch (error) {
return error.statusCode;
}
}
const statusCodeObj = {
americanas: yield getTurboRequestStatusCode('americanas'),
submarino: yield getTurboRequestStatusCode('submarino'),
shoptime: yield getTurboRequestStatusCode('shoptime'),
}
function getBrandsURLsActivenessFinalObj(brand) {
return {
active: statusCodeObj[brand] === httpStatus.OK,
url: brandsURLs[brand].url
}
}
return {
americanas: getBrandsURLsActivenessFinalObj('americanas'),
submarino: getBrandsURLsActivenessFinalObj('submarino'),
shoptime: getBrandsURLsActivenessFinalObj('shoptime'),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment