diff --git a/tournaments/templates/tournaments/broadcast/broadcasted_auto.html b/tournaments/templates/tournaments/broadcast/broadcasted_auto.html index d2d3257..dff76ea 100644 --- a/tournaments/templates/tournaments/broadcast/broadcasted_auto.html +++ b/tournaments/templates/tournaments/broadcast/broadcasted_auto.html @@ -43,7 +43,12 @@ prefixTitle: '', retrieveData() { fetch('/tournament/{{ tournament.id }}/broadcast/json/') - .then(res => res.json()) + .then(res => { + if (!res.ok) { + throw new Error(`HTTP ${res.status}: ${res.statusText}`); + } + return res.json(); + }) .then((data) => { this.paginatedMatches = this.paginate(data.matches, 8) this.paginatedGroupStages = this.paginate(data.group_stages, 4) @@ -56,6 +61,25 @@ this.active = 1; // Reset to the first page } }) + .catch((error) => { + console.error('Error fetching tournament data:', error); + + // If this tournament is in an iframe (part of event/club auto), notify parent + if (window.parent !== window) { + console.log('Notifying parent of tournament error'); + window.parent.postMessage({ + type: 'tournamentError', + tournamentId: '{{ tournament.id }}', + error: error.message + }, '*'); + } + + // Set empty data to prevent further errors + this.paginatedMatches = []; + this.paginatedGroupStages = []; + this.paginatedSummons = []; + this.paginatedRankings = []; + }) }, paginateSummons(array) { let pageSize = 16 diff --git a/tournaments/templates/tournaments/broadcast/broadcasted_club_auto.html b/tournaments/templates/tournaments/broadcast/broadcasted_club_auto.html index 54d079b..399649a 100644 --- a/tournaments/templates/tournaments/broadcast/broadcasted_club_auto.html +++ b/tournaments/templates/tournaments/broadcast/broadcasted_club_auto.html @@ -53,6 +53,10 @@ if (event.data.type === 'tournamentCycleComplete') { console.log(`Tournament completed (${event.data.reason})`); setTimeout(loadNextTournament, 1000); // Switch after 1 second + } else if (event.data.type === 'tournamentError') { + console.error(`Tournament ${event.data.tournamentId.substring(0, 8)} failed: ${event.data.error}`); + console.log('Switching to next tournament due to error...'); + setTimeout(loadNextTournament, 2000); // Switch after 2 seconds on error } }); diff --git a/tournaments/templates/tournaments/broadcast/broadcasted_event_auto.html b/tournaments/templates/tournaments/broadcast/broadcasted_event_auto.html index 69d8c90..b328665 100644 --- a/tournaments/templates/tournaments/broadcast/broadcasted_event_auto.html +++ b/tournaments/templates/tournaments/broadcast/broadcasted_event_auto.html @@ -53,6 +53,10 @@ if (event.data.type === 'tournamentCycleComplete') { console.log(`Tournament completed (${event.data.reason})`); setTimeout(loadNextTournament, 1000); // Switch after 1 second + } else if (event.data.type === 'tournamentError') { + console.error(`Tournament ${event.data.tournamentId.substring(0, 8)} failed: ${event.data.error}`); + console.log('Switching to next tournament due to error...'); + setTimeout(loadNextTournament, 2000); // Switch after 2 seconds on error } });