From 028ffe098b044bf1fbbd29f3476adf133584d252 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 22 Aug 2026 19:58:02 +0200 Subject: [PATCH] Report errors while loading the calendar The response of the fetch went to the parser without ever looking at it. When the calendar could not be loaded the error page of the web server was parsed as a calendar, which threw inside a promise nobody was waiting on. The result was an empty table, an unhandled rejection in the console and an error message about broken calendar syntax that says nothing about the actual problem, a calendar that is not there. Refuse a response that is not ok, naming the status, and log failures in the chain, like the calendar page already does. before: Uncaught (in promise) Error: invalid line (no token ";" or ":") "404 Not Found" after: Fehler beim Laden der Termine: Error: /calendars/all.ics: 404 Not Found The table stays empty either way, there is nothing to show without a calendar. Fixes: c28f04c6e85c ("switch to ics files; make calendars work; fix some minor issues") Assisted-by: Claude:claude-opus-5 Signed-off-by: Hauke Mehrtens --- static/js/upcoming.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/static/js/upcoming.js b/static/js/upcoming.js index c452467..0e2e266 100644 --- a/static/js/upcoming.js +++ b/static/js/upcoming.js @@ -101,7 +101,15 @@ document.addEventListener("DOMContentLoaded", () => { const table = document.getElementById("upcoming"); fetch(ics) - .then(response => response.text()) + .then(response => { + // Without this an error page would be handed to the parser below, which + // then fails with a confusing complaint about the calendar syntax. + if (!response.ok) { + throw new Error(`${ics}: ${response.status} ${response.statusText}`); + } + + return response.text(); + }) .then(icsText => { getUpcomingEvents(icsText, now, max_items, max_days).forEach(event => { const row = document.createElement("tr"); @@ -138,5 +146,6 @@ document.addEventListener("DOMContentLoaded", () => { table.appendChild(row); }); - }); + }) + .catch(err => console.error("Fehler beim Laden der Termine:", err)); });