From 5815c2b6d158f007ccb4d4ea5bbf0bdbea545e48 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 24 Oct 2024 04:26:00 -0500 Subject: [PATCH] frontend: error handling --- frontend/src/App.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f451ef9..385dc49 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -19,16 +19,22 @@ type SeenIP = { export default function App() { const [seenIps, setSeenIps] = useState([]); + const [error, setError] = useState(null); const refreshData = async () => { try { const response = await fetch(`${backendUrl}/ips`); + if (!response.ok) { + throw new Error(`Error: ${response.statusText}`); + } const data = await response.json(); setSeenIps(data.ips); + setError(null); // Clear any previous errors console.log('Data fetched:', data); } catch (error) { console.error('Error fetching data:', error); + setError(error.message); } }; @@ -51,6 +57,12 @@ export default function App() {

LinkPulse

+ {error && ( +
+ {error} +
+ )} +
@@ -60,12 +72,11 @@ export default function App() { {ip.ip} ))} -
- {ip.count} time{ip.count > 1 ? 's' : ''} + {ip.count} time{ip.count > 1 ? 's' : ''} {ip.last_seen}