Last active
December 27, 2018 12:22
-
-
Save steveast/d755c5f74d8c6b2bc04273f3b908c9f5 to your computer and use it in GitHub Desktop.
Собеседование: промис 2
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
const url = 'http://lol'; | |
function apiGet(url, attempts = 5) { | |
return new Promise(function core(resolve, reject) { | |
fetch(url) | |
.then((res) => { | |
resolve(res) | |
}) | |
.catch(() => { | |
if (attempts) { | |
attempts--; | |
core(resolve, reject); | |
} else { | |
reject('Error text') | |
} | |
}) | |
}); | |
} | |
apiGet(url) | |
.then((res) => { | |
console.log(res); | |
}) | |
.catch((err) => { | |
console.log(err) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment