From 2ada0e326b226270a1b9d552f7261357d810390d Mon Sep 17 00:00:00 2001 From: Panos Routsis <122146978+Addicti0n@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:31:22 +0200 Subject: [PATCH] Update LatestDocsVersion the component now checks for a successful HTTP response before proceeding to parse the JSON data. Also, I've wrapped the displayed version in a span element for better semantics. --- src/components/LatestDocsVersion | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/LatestDocsVersion b/src/components/LatestDocsVersion index c667f7a2..d9313317 100644 --- a/src/components/LatestDocsVersion +++ b/src/components/LatestDocsVersion @@ -12,18 +12,23 @@ const LatestDocsVersion = () => { 'X-GitHub-Api-Version': '2022-11-28', }, }) - .then(response => response.json()) - .then(data => { - setVersion(data.tag_name); - }) - .catch(error => { - console.error('Error fetching version:', error); - setVersion('Failed to load version'); - }); + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) + .then(data => { + setVersion(data.tag_name); + }) + .catch(error => { + console.error('Error fetching version:', error); + setVersion('Failed to load version'); + }); }, []); return ( - version || "N/A" + {version} // Wrapped in a span for potential styling or semantic purposes ); };