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:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user