We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b6d02e commit 08bf2d1Copy full SHA for 08bf2d1
fetch/programmer-humour/script.js
@@ -2,12 +2,15 @@ const fetchData = async () => {
2
const url = `https://xkcd.now.sh/?comic=latest`;
3
try {
4
const response = await fetch(url);
5
+
6
+ if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
7
8
const data = await response.json();
9
const imageEl = document.getElementById("image");
10
imageEl.src = data.img;
11
imageEl.alt = data.alt;
12
} catch (error) {
- console.log(`Error: ${error}`);
13
+ console.log(`Failed to fetch: ${error}`);
14
}
15
};
16
0 commit comments