Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-parrots-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: assign correct status code to form submission error on the client
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function form(id) {
void _goto(form_result.location, { invalidateAll }, 0);
} else {
result = undefined;
throw new HttpError(500, form_result.error);
throw new HttpError(form_result.status ?? 500, form_result.error);
}
} catch (e) {
result = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const task_one = form(async (form_data) => {
task = /** @type {string} */ (form_data.get('task'));

if (task === 'error') {
error(500, { message: 'Expected error' });
error(400, { message: 'Expected error' });
}
if (task === 'redirect') {
redirect(303, '/remote');
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@ test.describe('remote functions', () => {
await page.goto('/remote/form');
await page.fill('#input-task', 'error');
await page.click('#submit-btn-one');
expect(await page.textContent('h1')).toBe('400');
expect(await page.textContent('#message')).toBe(
'This is your custom error page saying: "Expected error"'
);
Expand All @@ -1635,6 +1636,7 @@ test.describe('remote functions', () => {
await page.goto('/remote/form');
await page.fill('#input-task', 'error');
await page.click('#submit-btn-two');
expect(await page.textContent('h1')).toBe('500');
expect(await page.textContent('#message')).toBe(
'This is your custom error page saying: "Unexpected error (500 Internal Error)"'
);
Expand Down
Loading