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