fix(web): surface a toast on failed mutations (#14)

Several client mutations either ignored a non-ok response (silent no-op) or
toasted success unconditionally even when the request failed. Sweep them so every
mutation gives feedback:

- artists: toggle auto-monitor, unfollow → error toast on failure.
- discography + wanted: toggle monitor / search-now → success or error toast.
- discover suggestion follow/want/dismiss → error toast (was toasting success
  even on failure).
- The Floor: queue request + retry → error toast on failure.
- artist-modal + preview follow/want, Last.fm want → error toast on failure
  (closes the deferred "want() shows no toast on non-ok" item).

web 153 tests, tsc + build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-14 13:25:31 +02:00
parent bc42e546f0
commit 7e5c083cef
8 changed files with 41 additions and 16 deletions
@@ -4,6 +4,7 @@ import { useEffect, useMemo, useState } from "react";
import { PageHead } from "../../_ui/page-head";
import { CoverArt } from "../../_ui/cover-art";
import { AlbumModal } from "../../_ui/album-modal";
import { toast } from "../../_ui/toast";
import { categoryOf, TAB_ORDER, type Category } from "../../_ui/categories";
type Release = {
@@ -39,15 +40,17 @@ export function DiscographyClient({ id }: { id: string }) {
}, [id]);
async function toggleMonitor(r: Release) {
await fetch(`/api/releases/${r.id}`, {
const res = await fetch(`/api/releases/${r.id}`, {
method: "PATCH",
headers: { "content-type": "application/json" },
body: JSON.stringify({ monitored: !r.monitored }),
});
}).catch(() => null);
if (!res?.ok) toast(`Couldn't update ${r.album}`);
refresh();
}
async function searchNow(r: Release) {
await fetch(`/api/releases/${r.id}/search`, { method: "POST" });
const res = await fetch(`/api/releases/${r.id}/search`, { method: "POST" }).catch(() => null);
toast(res?.ok ? `Searching for ${r.album}` : `Couldn't search for ${r.album}`);
refresh();
}