From 75f4262320b6a397dafa03e3084af541c4ea0249 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sun, 18 Jan 2026 23:59:55 +0100 Subject: [PATCH] Implement CSV fetching utility with retry logic in Mannschaften component This commit introduces a new utility function, fetchCsvText, to enhance the fetching of CSV data in the Mannschaften component. The function includes a cache-busting mechanism and retry logic to improve reliability when retrieving data from the server. Additionally, it updates the loadMannschaften function to utilize this new utility, ensuring better error handling and consistent data retrieval. These changes contribute to a more robust application. --- pages/cms/mannschaften.vue | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/pages/cms/mannschaften.vue b/pages/cms/mannschaften.vue index a1c024a..b22250e 100644 --- a/pages/cms/mannschaften.vue +++ b/pages/cms/mannschaften.vue @@ -463,6 +463,25 @@ function serializeSpielerNames(spielerNames) { .join('; ') } +async function fetchCsvText(url) { + const attempt = async () => { + const withBuster = `${url}${url.includes('?') ? '&' : '?'}_t=${Date.now()}` + const response = await fetch(withBuster, { cache: 'no-store' }) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + return await response.text() + } + + try { + return await attempt() + } catch (e) { + // 1 Retry: hilft bei Firefox NS_ERROR_NET_PARTIAL_TRANSFER direkt nach Speichern + await new Promise(resolve => setTimeout(resolve, 150)) + return await attempt() + } +} + const mannschaftenSelectOptions = computed(() => { const current = (formData.value.mannschaft || '').trim() const names = mannschaften.value @@ -489,14 +508,7 @@ function getPendingSpielerNamesForTeamIndex(teamIndex) { const loadMannschaften = async () => { isLoading.value = true try { - // Cache-Buster: Browser/CDN könnten CSV sonst aggressiv cachen - const url = `/data/mannschaften.csv?_t=${Date.now()}` - const response = await fetch(url, { cache: 'no-store' }) - if (!response.ok) { - throw new Error('Fehler beim Laden der Mannschaften') - } - - const csv = await response.text() + const csv = await fetchCsvText('/data/mannschaften.csv') const lines = csv.split('\n').filter(line => line.trim() !== '') if (lines.length < 2) { @@ -542,6 +554,7 @@ const loadMannschaften = async () => { } catch (error) { console.error('Fehler beim Laden der Mannschaften:', error) errorMessage.value = 'Fehler beim Laden der Mannschaften' + throw error } finally { isLoading.value = false } @@ -809,7 +822,7 @@ const confirmDelete = (mannschaft, index) => { } onMounted(() => { - loadMannschaften() + loadMannschaften().catch(() => {}) }) definePageMeta({