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 ":")
"<html>404 Not Found</html>"
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: c28f04c6e8 ("switch to ics files; make calendars work; fix some minor issues")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
parent
d9ec622055
commit
028ffe098b
1 changed files with 11 additions and 2 deletions
|
|
@ -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));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue