Skip to content

Commit 1c032cb

Browse files
first part of week3 homework is finished
1 parent 6d15d72 commit 1c032cb

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

homework/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<section class="contributors-container"></section>
2828
</main>
2929
</div>
30+
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
3031
<script src="index.js"></script>
3132
</body>
3233
</html>

homework/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
'use strict';
22

33
{
4-
function fetchJSON(url, cb) {
5-
fetch(url)
6-
.then((response) => {
7-
if (!response.ok) {
8-
throw new Error(
9-
`Network error: ${response.status} - ${response.statusText}`,
10-
);
11-
}
12-
return response.json();
13-
})
14-
.then((data) => cb(null, data))
15-
.catch((error) => cb(error, null));
4+
async function fetchJSON(url, cb) {
5+
try {
6+
const response = await axios.get(url)
7+
const data = response.data
8+
cb(null, data)
9+
} catch (error) {
10+
cb(error, null)
11+
}
1612
}
1713

1814
function createAndAppend(name, parent, options = {}) {

0 commit comments

Comments
 (0)