refactoring, modules
This commit is contained in:
parent
b8f6d96990
commit
a16814aaf1
112 changed files with 484 additions and 1825 deletions
|
@ -1,33 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<script>
|
||||
|
||||
// the whole promise chain fails with an error here
|
||||
// change that:
|
||||
// make errors appear as members of the results array
|
||||
|
||||
let urls = [
|
||||
'https://api.github.com/users/iliakan',
|
||||
// this URL is HTML page, it's invalid JSON, so response.json() fails
|
||||
'/',
|
||||
// this URL is invalid, so fetch fails
|
||||
'http://no-such-url'
|
||||
];
|
||||
|
||||
// Fix it:
|
||||
Promise.all(urls.map(url => fetch(url)))
|
||||
.then(responses => Promise.all(
|
||||
responses.map(r => r.json())
|
||||
))
|
||||
// Demo output (no need to change):
|
||||
.then(results => {
|
||||
alert(results[0].name); // Ilya Kantor
|
||||
alert(results[1]); // SyntaxError: Unexpected token < in JSON at position 0
|
||||
alert(results[2]); // TypeError: failed to fetch (text may vary)
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue