Implement CSV fetching utility across components for improved data handling
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 46s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 46s
This commit introduces a new utility function, fetchCsvText, to streamline the fetching of CSV data across multiple components. The function includes a cache-busting mechanism and retry logic to enhance reliability when retrieving data from the server. This change improves error handling and ensures consistent data retrieval in the Mannschaften overview, detail, and schedule pages, contributing to a more robust application.
This commit is contained in:
@@ -923,10 +923,22 @@ const toggleMobileSubmenu = (menu) => {
|
||||
|
||||
const loadMannschaften = async () => {
|
||||
try {
|
||||
const response = await fetch('/data/mannschaften.csv')
|
||||
if (!response.ok) return
|
||||
const attempt = async () => {
|
||||
const url = `/data/mannschaften.csv?_t=${Date.now()}`
|
||||
const response = await fetch(url, { cache: 'no-store' })
|
||||
if (!response.ok) return null
|
||||
return await response.text()
|
||||
}
|
||||
|
||||
const csv = await response.text()
|
||||
let csv = null
|
||||
try {
|
||||
csv = await attempt()
|
||||
} catch (_e) {
|
||||
// 1 Retry: hilft bei kurzen Restarts/Proxy-Resets (Firefox: NS_ERROR_NET_PARTIAL_TRANSFER)
|
||||
await new Promise(resolve => setTimeout(resolve, 150))
|
||||
csv = await attempt()
|
||||
}
|
||||
if (!csv) return
|
||||
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
||||
|
||||
if (lines.length < 2) return
|
||||
|
||||
Reference in New Issue
Block a user