@@ -43,6 +43,7 @@ let locale = url.searchParams.get("lang") || "de";
4343
4444
4545const calendarContainer = document . getElementById ( "calendar" ) ;
46+ const errorBar = document . getElementById ( "errorbar" ) ;
4647const sourceInfo = document . getElementById ( "sourceInfo" ) ;
4748const yearSelect = document . getElementById ( "yearSelect" ) ;
4849const countryList = document . getElementById ( "countryList" ) ;
@@ -74,9 +75,11 @@ document.addEventListener("DOMContentLoaded", async () => {
7475 renderCountrySelection ( ) ;
7576 await updateCalendar ( ) ;
7677 } catch ( e ) {
77- calendarContainer . innerHTML = e . message + `<br/><a href=".">Reload page</a>` ;
78+ errorBar . innerHTML = "Error: " + e . message + `<br/><a href=".">Reload page</a>` ;
79+ errorBar . style . display = "block" ;
7880 throw e
7981 }
82+ errorBar . style . display = "none" ;
8083
8184 shareLinkButton . text = i18n . share
8285
@@ -238,26 +241,35 @@ async function fetchRegionData(countryCode) {
238241// ------------------------------------------------------------
239242// Aktualisiere Kalender
240243async function updateCalendar ( ) {
241- const [ fromStr , toStr ] = selectedMonthRange . split ( "~" ) ;
242- const fromDate = new Date ( fromStr ) ;
243- let toDate = new Date ( toStr ) ;
244- if ( ! fromDate || isNaN ( fromDate ) || ! toDate || isNaN ( toDate ) || toDate < fromDate || toDate - fromDate > 2 * 365 * 24 * 60 * 60 * 1000 )
245- throw Error ( "Invalid date range " + selectedMonthRange ) ;
246-
247- // Lade Daten, falls noch nicht vorhanden
248- const fetch = [ ] ;
249- if ( ! populationData ) fetch . push ( fetchPopulationData ( ) ) ;
250- for ( let country of selectedCountries ) {
251- if ( ! cachedData . Regions [ country ] ) fetch . push ( fetchRegionData ( country ) ) ;
252- for ( let year of [ ...new Set ( [ fromDate . getFullYear ( ) , toDate . getFullYear ( ) ] ) ] ) {
253- if ( ! cachedData [ year ] || ! cachedData [ year ] [ country ] ) fetch . push ( fetchCountryData ( year , country ) ) ;
244+ try {
245+ const [ fromStr , toStr ] = selectedMonthRange . split ( "~" ) ;
246+ const fromDate = new Date ( fromStr ) ;
247+ let toDate = new Date ( toStr ) ;
248+ if ( ! fromDate || isNaN ( fromDate ) || ! toDate || isNaN ( toDate ) || toDate < fromDate || toDate - fromDate > 2 * 365 * 24 * 60 * 60 * 1000 )
249+ throw Error ( "Invalid date range " + selectedMonthRange ) ;
250+
251+ // Lade Daten, falls noch nicht vorhanden
252+ const fetch = [ ] ;
253+ if ( ! populationData ) fetch . push ( fetchPopulationData ( ) ) ;
254+ for ( let country of selectedCountries ) {
255+ if ( ! cachedData . Regions [ country ] ) fetch . push ( fetchRegionData ( country ) ) ;
256+ for ( let year of [ ...new Set ( [ fromDate . getFullYear ( ) , toDate . getFullYear ( ) ] ) ] ) {
257+ if ( ! cachedData [ year ] || ! cachedData [ year ] [ country ] ) fetch . push ( fetchCountryData ( year , country ) ) ;
258+ }
254259 }
260+ await Promise . all ( fetch ) ;
261+
262+ // Daten aggregieren
263+ const stats = calculateDayStatistics ( fromDate , toDate ) ;
264+ renderCalendar ( stats ) ;
265+
266+ } catch ( e ) {
267+ errorBar . innerHTML = "Error: " + e . message + `<br/><a href=".">Reload page</a>` ;
268+ errorBar . style . display = "block" ;
269+ throw e
255270 }
256- await Promise . all ( fetch ) ;
271+ errorBar . style . display = "none" ;
257272
258- // Daten aggregieren
259- const stats = calculateDayStatistics ( fromDate , toDate ) ;
260- renderCalendar ( stats ) ;
261273}
262274
263275// ------------------------------------------------------------
0 commit comments