Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 228e66d

Browse files
committed
update
1 parent 1ed91d1 commit 228e66d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

homework/Util.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@ class Util {
1717
}
1818

1919
static fetchJSON(url) {
20-
return new Promise((resolve, reject) => {
21-
fetch(url)
22-
.then(response => {
23-
if (!response.ok) {
24-
reject(new Error(`Network request failed`));
25-
}
26-
return response.json();
27-
})
28-
.then(response => resolve(response))
29-
.catch(error => {
30-
reject(new Error(`Network error: ${error.message}`));
31-
});
20+
return fetch(url).then(response => {
21+
if (!response.ok) {
22+
throw new Error(`Network request failed`);
23+
}
24+
return response.json();
3225
});
3326
}
3427
}

0 commit comments

Comments
 (0)