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