From f51cbd438a07538d51bb017e77eb76c64787692b Mon Sep 17 00:00:00 2001 From: "user@node5.net" Date: Fri, 10 Jul 2026 14:09:43 +0200 Subject: update - handle errors retain content, log what happened, show indicator in bar --- src/static/main.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/static/main.js b/src/static/main.js index 45b7f9b..0900c41 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -1,9 +1,23 @@ +topE = document.querySelector("#top"); +programE = document.querySelector("#program"); + async function update() { - const html = await (await fetch("/update")).text(); - document.querySelector("#top").innerHTML = html.split("\n").slice(0, 1)[0]; - document.querySelector("#program").outerHTML = html.split("\n").slice(1).join("\n"); + try { + const response = await fetch("/update"); + if (response.status == 200) { + html = await response.text(); + topE.innerHTML = html.split("\n").slice(0, 1)[0]; + programE.outerHTML = html.split("\n").slice(1).join("\n"); + } + } catch (err) { + // Happens when the server is closed / unreachable + if (!topE.textContent.endsWith("❗")) { + topE.textContent = (topE.textContent.slice(0, -1) || topE.textContent) + "❗"; + } + console.log("Fetch failed:", err); + } } setInterval(() => { - update() + update() }, 5000); -- cgit v1.3.1