Created
May 26, 2022 18:06
-
-
Save ViniciusResende/3135fa9cb15917c383868983ed83ed98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| *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