fix(journey-create): catch network rejections and surface error alert

try/finally without catch swallowed TypeError network failures silently.
Added catch block that sets errorMessage so the UI shows role=alert.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-10 19:41:11 +02:00
parent 166003b33a
commit b0d75b26cd
2 changed files with 19 additions and 0 deletions

View File

@@ -38,6 +38,9 @@ async function handleSubmit(e: SubmitEvent) {
}
const created = await res.json();
goto(`/geschichten/${created.id}/edit`);
} catch (e) {
console.error('JourneyCreate submit failed', e);
errorMessage = getErrorMessage(undefined);
} finally {
submitting = false;
}

View File

@@ -62,6 +62,22 @@ describe('JourneyCreate — failure path', () => {
});
});
it('shows an error alert when the network request rejects (no crash)', async () => {
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new TypeError('network down')));
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
render(JourneyCreate, {});
await userEvent.fill(
page.getByRole('textbox', { name: m.journey_title_aria_label() }),
'Meine Lesereise'
);
await userEvent.click(page.getByRole('button', { name: m.journey_create_submit() }));
await expect.element(page.getByRole('alert')).toBeInTheDocument();
consoleError.mockRestore();
});
it('has an accessible label on the title input', async () => {
vi.stubGlobal('fetch', vi.fn());
render(JourneyCreate, {});