Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment