feat: add error handling to player core functions

This commit is contained in:
2026-06-16 14:00:38 +02:00
committed by Milas Holsting
parent 3a1a2129d9
commit 2a8294c405
9 changed files with 45 additions and 22 deletions

View File

@@ -211,7 +211,12 @@ export const setupSegmentEditor = (): void => {
});
if (!res.ok) {
let message = res.status === 401 ? "Login required." : "Failed to save segment.";
const payload = (await res.json().catch(() => null)) as { error?: string } | null;
let payload: { error?: string } | null = null;
try {
payload = await res.json();
} catch (error) {
console.error("failed to parse response json:", error);
}
if (payload?.error) message = payload.error;
setError(message);
return;
@@ -235,8 +240,10 @@ export const setupSegmentEditor = (): void => {
window.showToast?.({ message: "Segment saved." });
close();
} catch {
setError("Failed to save segment.");
} catch (error) {
setError("Failed To Save Segment.");
console.error("failed to save segment:", error);
throw error;
} finally {
saveBtn.disabled = false;
saveBtn.classList.remove("opacity-70");