From f043dd62d856caf78b2de03944c9daefc42f69c9 Mon Sep 17 00:00:00 2001 From: Priveetee Date: Sun, 10 May 2026 20:03:10 +0200 Subject: [PATCH] fix: surface failed delete responses --- apps/web/src/lib/api-collections.ts | 16 ++++++++++++++-- apps/web/src/lib/api-playlists.ts | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/web/src/lib/api-collections.ts b/apps/web/src/lib/api-collections.ts index d637b00..5c9b7fa 100644 --- a/apps/web/src/lib/api-collections.ts +++ b/apps/web/src/lib/api-collections.ts @@ -4,6 +4,12 @@ import { authed, authedJson } from "./authed"; import { API_BASE as BASE } from "./env"; +async function throwIfFailed(res: Response, fallback: string): Promise { + if (res.ok) return; + const body = await res.json().catch(() => ({ error: fallback })); + throw new ApiError((body as { error: string }).error, res.status); +} + export async function fetchProgress(videoUrl: string): Promise { const res = await authed(`${BASE}/progress/${encodeURIComponent(videoUrl)}`); if (res.status === 404) return { videoUrl, position: 0, updatedAt: 0 }; @@ -42,7 +48,10 @@ export async function blockChannel( } export async function unblockChannel(url: string): Promise { - await authed(`${BASE}/blocked/channels/${encodeURIComponent(url)}`, { method: "DELETE" }); + const res = await authed(`${BASE}/blocked/channels/${encodeURIComponent(url)}`, { + method: "DELETE", + }); + await throwIfFailed(res, "unblock failed"); } export function fetchBlockedVideos(): Promise { @@ -58,5 +67,8 @@ export async function blockVideo(url: string, global = false): Promise { } export async function unblockVideo(url: string): Promise { - await authed(`${BASE}/blocked/videos/${encodeURIComponent(url)}`, { method: "DELETE" }); + const res = await authed(`${BASE}/blocked/videos/${encodeURIComponent(url)}`, { + method: "DELETE", + }); + await throwIfFailed(res, "unblock failed"); } diff --git a/apps/web/src/lib/api-playlists.ts b/apps/web/src/lib/api-playlists.ts index 43eeccd..77d2a9f 100644 --- a/apps/web/src/lib/api-playlists.ts +++ b/apps/web/src/lib/api-playlists.ts @@ -50,7 +50,7 @@ export async function removeVideoFromPlaylist(playlistId: string, videoUrl: stri `${BASE}/playlists/${encodeURIComponent(playlistId)}/videos/${encodeURIComponent(videoUrl)}`, { method: "DELETE" }, ); - if (!res.ok && res.status !== 404) { + if (!res.ok) { const body = await res.json().catch(() => ({ error: "remove failed" })); throw new ApiError((body as { error: string }).error, res.status); }