fix(web): error handling on discard and history toggle

- LabDraft.tsx discard button: chain .catch to surface a failed discard in
  the existing error banner instead of an unhandled rejection.
- LabDraw.tsx toggleHistory: wrap the marker-history fetch in try/catch so a
  failed request silently no-ops (the row just doesn't expand) rather than
  throwing unhandled from the click handler.
This commit is contained in:
marcuspaico
2026-08-17 16:17:03 -07:00
parent e81d07975a
commit a9256a765f
2 changed files with 19 additions and 3 deletions

View File

@@ -80,7 +80,18 @@ export function LabDraft() {
<button disabled={busy || !collectedDate || markers.length === 0} onClick={confirm}> <button disabled={busy || !collectedDate || markers.length === 0} onClick={confirm}>
{busy ? "Saving…" : `Confirm ${markers.length} markers`} {busy ? "Saving…" : `Confirm ${markers.length} markers`}
</button> </button>
<button className="danger" onClick={() => id && api.discardDraft(id).then(() => nav("/labs"))}>Discard</button> <button
className="danger"
onClick={() =>
id &&
api
.discardDraft(id)
.then(() => nav("/labs"))
.catch((e) => setError(e instanceof Error ? e.message : "discard failed"))
}
>
Discard
</button>
</div> </div>
)} )}
</section> </section>

View File

@@ -17,8 +17,13 @@ export function LabDraw() {
setHistory((h) => { const { [key]: _, ...rest } = h; return rest; }); setHistory((h) => { const { [key]: _, ...rest } = h; return rest; });
return; return;
} }
const h = await api.markerHistory(key); try {
setHistory((prev) => ({ ...prev, [key]: h })); const h = await api.markerHistory(key);
setHistory((prev) => ({ ...prev, [key]: h }));
} catch {
// Silently no-op: history is a supplemental, click-to-expand feature —
// a failed fetch should never throw unhandled or break the row.
}
}; };
if (!detail) return <p>Loading…</p>; if (!detail) return <p>Loading…</p>;