Guest User

Untitled

a guest
Oct 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. async function getStarWarsHeroes() {
  2. let retryLimit = 3;
  3. let success = false;
  4. // API is not always returning data (500 erros happens) so we extend your tries to 3 times that explain a for loop
  5. for (let it = 0; it < retryLimit; ++it) {
  6. let data = await axios.get('...')
  7. .then(response => response.json())
  8. .then(json => {
  9. success = true;
  10. return json;
  11. }
  12. .catch(error => {
  13. console.error(error);
  14. })
  15. if (success === true) {
  16. return data;
  17. }
  18. }
  19. return null;
  20. }
Add Comment
Please, Sign In to add comment