From 45534aa8ee4bf66d99766dffbc9b74f105164e30 Mon Sep 17 00:00:00 2001 From: rene Date: Sat, 6 Jun 2026 11:42:05 +0200 Subject: [PATCH] Sweep: r.ok-Check bei allen direkten fetch('/api/...')-Aufrufen (SW-503-JSON-Falle) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5 Fundstellen nach dem Marker-Bug-Muster (v1224) gefixt: - landing-init.js: Stats-Zahlen waeren offline NaN geworden - social.js: Medien-Upload-Fehler wurde verschluckt (kein ok-Check, kein catch) - routes.js: Unterwegs-POIs — {detail:...}.filter warf statt sauber [] - map.js: Marker-Melden zeigte Erfolgs-Toast obwohl Request fehlschlug - settings.js: Update-Check meldete offline faelschlich 'ist aktuell' Rest geprueft: api.js-Wrapper, wiki/uebungen/trainingsplaene-Helper checken ok, externe Dienste (Nominatim etc.) laufen nicht ueber den SW-/api/-Zweig. Bump v1225 --- VERSION | 2 +- backend/static/index.html | 24 ++++++++++++------------ backend/static/js/app.js | 2 +- backend/static/js/landing-init.js | 3 ++- backend/static/js/pages/map.js | 3 +++ backend/static/js/pages/routes.js | 7 +++++-- backend/static/js/pages/settings.js | 3 +++ backend/static/js/pages/social.js | 7 ++++++- backend/static/landing.html | 2 +- backend/static/sw.js | 2 +- 10 files changed, 35 insertions(+), 20 deletions(-) diff --git a/VERSION b/VERSION index 7aee5ac..337173d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1224 \ No newline at end of file +1225 \ No newline at end of file diff --git a/backend/static/index.html b/backend/static/index.html index bfd8dd9..59761f6 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -86,14 +86,14 @@ Ban Yaro - + - - - - - + + + + + @@ -612,11 +612,11 @@ - - - - - + + + + + @@ -626,7 +626,7 @@ - + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 204d3f4..27286f7 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '1224'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '1225'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator) window.APP_VERSION = APP_VERSION; diff --git a/backend/static/js/landing-init.js b/backend/static/js/landing-init.js index b4bcb53..ada2d1d 100644 --- a/backend/static/js/landing-init.js +++ b/backend/static/js/landing-init.js @@ -64,7 +64,8 @@ document.addEventListener('DOMContentLoaded', function() { // Live-Zahlen var fmt = new Intl.NumberFormat('de-DE'); fetch('/api/stats/public') - .then(function(r) { return r.json(); }) + // r.ok prüfen: der SW antwortet offline mit 503+JSON ({detail:…}) → json() wirft nicht + .then(function(r) { if (!r.ok) throw new Error('stats ' + r.status); return r.json(); }) .then(function(d) { function set(id, val) { var el = document.getElementById(id); diff --git a/backend/static/js/pages/map.js b/backend/static/js/pages/map.js index 2692cff..06e77e1 100644 --- a/backend/static/js/pages/map.js +++ b/backend/static/js/pages/map.js @@ -1865,6 +1865,9 @@ window.Page_map = (() => { credentials: 'include', body: JSON.stringify(body), }); if (res.status === 401) { UI.toast.error('Bitte erst anmelden.'); return; } + // res.ok prüfen: SW antwortet offline mit 503+JSON → json() wirft nicht, + // sonst Erfolgs-Toast obwohl nichts gemeldet wurde. (202 = offline gequeued = ok.) + if (!res.ok) throw new Error(`report ${res.status}`); const data = await res.json(); if (data.status === 'bereits_gemeldet') { UI.toast.info('Du hast diesen Marker bereits gemeldet.'); diff --git a/backend/static/js/pages/routes.js b/backend/static/js/pages/routes.js index 23e3381..4686f15 100644 --- a/backend/static/js/pages/routes.js +++ b/backend/static/js/pages/routes.js @@ -2762,8 +2762,11 @@ window.Page_routes = (() => { await Promise.all(NEARBY_TYPES.map(async ({ type, icon, label, svgIcon, color }) => { try { const params = new URLSearchParams({ type, fast: 'true', ...bbox }); - const pois = await fetch(`/api/osm/pois?${params}`).then(r => r.json()); - pois + // r.ok prüfen: SW antwortet offline mit 503+JSON ({detail:…}) → json() wirft nicht + const r = await fetch(`/api/osm/pois?${params}`); + if (!r.ok) throw new Error(`pois ${r.status}`); + const pois = await r.json(); + (Array.isArray(pois) ? pois : []) .filter(p => _isNearTrack(p, track, 100)) // max 100m vom Track-Verlauf .forEach(p => results.push({ ...p, _icon: icon, _label: label, _svgIcon: svgIcon, _color: color })); } catch {} diff --git a/backend/static/js/pages/settings.js b/backend/static/js/pages/settings.js index e59aaeb..a9446bb 100644 --- a/backend/static/js/pages/settings.js +++ b/backend/static/js/pages/settings.js @@ -1346,6 +1346,9 @@ window.Page_settings = (() => { try { // Versionsnummer direkt vom API-Endpunkt holen const r = await fetch('/api/version', { cache: 'no-store' }); + // r.ok prüfen: SW antwortet offline mit 503+JSON → json() wirft nicht und + // serverVersion=undefined meldete fälschlich „Ban Yaro ist aktuell". + if (!r.ok) throw new Error(`version ${r.status}`); const { version: serverVersion } = await r.json(); const localVersion = typeof APP_VER !== 'undefined' ? APP_VER : '0'; diff --git a/backend/static/js/pages/social.js b/backend/static/js/pages/social.js index 4a81765..b87cf8d 100644 --- a/backend/static/js/pages/social.js +++ b/backend/static/js/pages/social.js @@ -377,7 +377,12 @@ window.Page_social = (() => { method: 'POST', headers: {Authorization: `Bearer ${localStorage.getItem('by_token')}`}, body: fd, - }).then(r => r.json()).then(d => { uploadedMediaUrl = d.url; }); + }).then(r => { + // r.ok prüfen: SW antwortet offline mit 503+JSON → json() wirft nicht, d.url wäre undefined + if (!r.ok) throw new Error(`upload ${r.status}`); + return r.json(); + }).then(d => { uploadedMediaUrl = d.url; }) + .catch(() => UI.toast.error('Medien-Upload fehlgeschlagen.')); }; reader.readAsDataURL(file); } diff --git a/backend/static/landing.html b/backend/static/landing.html index 9b7b061..aafb5f5 100644 --- a/backend/static/landing.html +++ b/backend/static/landing.html @@ -4,7 +4,7 @@ - + Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz diff --git a/backend/static/sw.js b/backend/static/sw.js index 8c51cc9..6e5fb87 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -4,7 +4,7 @@ ============================================================ */ // ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab -const VER = '1224'; +const VER = '1225'; const CACHE_VERSION = `by-v${VER}`; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten