feat(queue): 404 on unknown hash, show error in UI

POST /api/queue/cancel answers 404 {"error":"hash not in queue"} for
untracked hashes instead of 200 ok:true. The UI surfaces the server's
error message instead of swallowing it.
This commit is contained in:
2026-10-19 19:11:40 +02:00
parent 44c2888a2e
commit 99dcb298f8
8 changed files with 297 additions and 52 deletions

View File

@@ -11,11 +11,18 @@ async function apiFetch(path, opts) {
...(opts && opts.headers),
},
});
const ct = res.headers.get('content-type') || '';
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `HTTP ${res.status}`);
let msg = text || `HTTP ${res.status}`;
if (ct.includes('application/json')) {
try {
const data = JSON.parse(text);
if (data && data.error) msg = data.error;
} catch {} // Malformed JSON: keep the raw text
}
throw new Error(msg);
}
const ct = res.headers.get('content-type') || '';
if (ct.includes('application/json')) return res.json();
return res.text();
}
@@ -209,8 +216,11 @@ function renderQueue() {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ hash }),
});
} catch {}
renderQueue();
renderQueue();
} catch {
btn.textContent = '[err]';
setTimeout(() => { btn.disabled = false; btn.textContent = '[x]'; }, 2000);
}
});
});
}).catch(err => {