HOTFIX: useMutation.run returns MutationOutcome (no throw); sweep all 7 call sites + README convention

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 00:44:56 +02:00
parent 3476b71525
commit 27299e225c
8 changed files with 54 additions and 40 deletions

View File

@@ -42,16 +42,14 @@ export default function BeckenDetailPage() {
async function onDelete() {
if (!window.confirm(t.delete.confirmMessage)) return
setDeleteError(null)
try {
await removal.run()
const result = await removal.run()
if (result.ok) {
navigate('/becken')
} catch (err) {
} else if (result.cause instanceof ApiError && result.cause.status === 409) {
// Backend meldet Konflikt, wenn noch Tiere im Becken wohnen.
if (err instanceof ApiError && err.status === 409) {
setDeleteError(t.delete.conflict)
} else {
setDeleteError(removal.error ?? de.api.errors.unknown)
}
setDeleteError(t.delete.conflict)
} else {
setDeleteError(result.error)
}
}

View File

@@ -44,8 +44,9 @@ export default function BeckenFormPage() {
return
}
setErrors({})
const saved = await mutation.run({ name: form.name.trim(), notes: nn(form.notes) })
navigate(`/becken/${saved.id}`)
const result = await mutation.run({ name: form.name.trim(), notes: nn(form.notes) })
if (result.ok) navigate(`/becken/${result.value.id}`)
// On failure mutation.error drives the inline alert; run() never throws.
}
if (isEdit && existing.loading) return <p className="muted">{de.common.loading}</p>

View File

@@ -166,13 +166,9 @@ export default function GerbilFormPage() {
genotype: nn(form.genotype),
notes: nn(form.notes),
}
try {
const saved = await mutation.run(body)
navigate(`/rennmaeuse/${saved.id}`)
} catch {
// Error is surfaced via mutation.error; swallow so the rejected promise
// from this async submit handler doesn't become an unhandled rejection.
}
const result = await mutation.run(body)
if (result.ok) navigate(`/rennmaeuse/${result.value.id}`)
// On failure mutation.error drives the inline alert; run() never throws.
}
if (isEdit && existing.loading) return <p className="muted">{de.common.loading}</p>

View File

@@ -45,16 +45,14 @@ export default function KontaktDetailPage() {
async function onDelete() {
if (!window.confirm(t.delete.confirmMessage)) return
setDeleteError(null)
try {
await removal.run()
const result = await removal.run()
if (result.ok) {
navigate('/kontakte')
} catch (err) {
} else if (result.cause instanceof ApiError && result.cause.status === 409) {
// Backend meldet Konflikt, wenn der Kontakt noch referenziert wird.
if (err instanceof ApiError && err.status === 409) {
setDeleteError(t.delete.conflict)
} else {
setDeleteError(removal.error ?? de.api.errors.unknown)
}
setDeleteError(t.delete.conflict)
} else {
setDeleteError(result.error)
}
}

View File

@@ -52,12 +52,13 @@ export default function KontaktFormPage() {
return
}
setErrors({})
const saved = await mutation.run({
const result = await mutation.run({
name: form.name.trim(),
contactInfo: nn(form.contactInfo),
notes: nn(form.notes),
})
navigate(`/kontakte/${saved.id}`)
if (result.ok) navigate(`/kontakte/${result.value.id}`)
// On failure mutation.error drives the inline alert; run() never throws.
}
if (isEdit && existing.loading) return <p className="muted">{de.common.loading}</p>

View File

@@ -116,13 +116,9 @@ export default function WurfFormPage() {
expectedGoHomeDate: nn(form.expectedGoHomeDate),
notes: nn(form.notes),
}
try {
const saved = await mutation.run(body)
navigate(`/wuerfe/${saved.id}`)
} catch {
// Error surfaced via mutation.error; swallow to avoid an unhandled
// rejection escaping this async submit handler.
}
const result = await mutation.run(body)
if (result.ok) navigate(`/wuerfe/${result.value.id}`)
// On failure mutation.error drives the inline alert; run() never throws.
}
if (isEdit && existing.loading) return <p className="muted">{de.common.loading}</p>