We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 29b7851 commit b19c286Copy full SHA for b19c286
fetch/fetch-promise/enhanced-fetch.js
@@ -0,0 +1,33 @@
1
+const output = document.getElementById("output");
2
+const btn = document.getElementById("btn");
3
+const input = document.getElementById("input");
4
+
5
+const url = fetch("https://randomuser.me/api");
6
7
+const fetchAPI = () => {
8
+ url
9
+ .then(
10
+ (response) => {
11
+ if (!response.ok) throw response.statusText;
12
+ return response.clone().json();
13
+ },
14
+ (err) => {
15
+ //! first level catch/interrupt
16
+ //the fetch failing
17
+ console.log("server error");
18
+ }
19
+ )
20
21
+ (data) => {
22
+ console.log(data);
23
24
25
+ //! failed to run response.json()
26
+ console.log(" error");
27
28
29
+ .catch((err) => {
30
+ console.log("network error");
31
+ });
32
+};
33
+btn.addEventListener("click", fetchAPI);
0 commit comments