fix: add 90s timeout to Spotify resolve fetch, prevent infinite spinner

Frontend fetch to /api/spotify/resolve had no timeout — if the backend
stalled (Spotify API slow or unreachable), the spinner would never stop.
Also caps the health check at 5s so loadSpotifyImporter can't hang.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-09 23:32:38 +02:00
1 parent f7e4059f2d
commit 7d38fdf601
1 file changed
+6 -1
+6 -1
View File
@@ -16,7 +16,7 @@ export async function loadSpotifyImporter() {
if (S.cfg.backendUrl) {
try {
const h = await fetch(`${S.cfg.backendUrl}/api/health`).then(r => r.json());
const h = await fetch(`${S.cfg.backendUrl}/api/health`, { signal: AbortSignal.timeout(5000) }).then(r => r.json());
if (!h.spotify?.configured) {
const input = document.getElementById('spotify-link-input');
if (input) {
@@ -63,6 +63,7 @@ export async function resolveSpotifyLink() {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url }),
signal: AbortSignal.timeout(90000),
});
if (!res.ok) {
const err = await res.json().catch(() => ({}));
@@ -74,6 +75,10 @@ export async function resolveSpotifyLink() {
if (data.skippedLocal > 0) toast(`${data.skippedLocal} lokale Datei(en) übersprungen (kein Stream verfügbar)`);
_renderSpotifyPreview(data);
} catch(e) {
if (e.name === 'TimeoutError' || e.name === 'AbortError') {
inner.innerHTML = `<div style="color:var(--danger);padding:16px;background:var(--surface);border-radius:10px">Zeitüberschreitung — der Server hat nicht rechtzeitig geantwortet. Läuft das Backend?</div>`;
return;
}
if (e.message === 'EDITORIAL_PLAYLIST') {
inner.innerHTML = `<div style="padding:16px;background:var(--surface);border-radius:10px;border-left:3px solid #1DB954">
<div style="font-weight:600;margin-bottom:10px;color:#1DB954">💡 Editorial Playlist erkannt</div>