Last active
October 19, 2018 14:25
-
-
Save 1n3ffbl3/016c5ad552a75ebe7d9c1289f45613dc to your computer and use it in GitHub Desktop.
Piece of code
This file contains 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
async function getStarWarsHeroes() { | |
let retryLimit = 3; | |
let success = false; | |
// API is not always returning data (500 erros happens) so we extend your tries to 3 times that explain a for loop | |
for (let it = 0; it < retryLimit; ++it) { | |
let data = await axios.get('...') | |
.then(response => response.json()) | |
.then(json => { | |
success = true; | |
return json; | |
} | |
.catch(error => { | |
console.error(error); | |
}) | |
if (success === true) { | |
return data; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment