Skip to content

Commit

Permalink
fix: revert recent error changes (#11295)
Browse files Browse the repository at this point in the history
We shouldn't have merged #11255 and #11278. They were reasonable changes on the face of it, but they were the wrong fix because it breaks apps for people that implement their own App.Error interface
  • Loading branch information
Rich-Harris committed Dec 13, 2023
1 parent b2b1951 commit 86a1357
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-radios-tell.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: revert recent 'correctly return 415' and 'correctly return 404' changes
5 changes: 2 additions & 3 deletions packages/kit/src/runtime/server/page/actions.js
Expand Up @@ -216,12 +216,11 @@ async function call_action(event, actions) {

const action = actions[name];
if (!action) {
throw error(404, `No action with name '${name}' found`);
throw new Error(`No action with name '${name}' found`);
}

if (!is_form_content_type(event.request)) {
throw error(
415,
throw new Error(
`Actions expect form-encoded data (received ${event.request.headers.get('content-type')})`
);
}
Expand Down
36 changes: 0 additions & 36 deletions packages/kit/test/apps/basics/test/test.js
Expand Up @@ -1242,42 +1242,6 @@ test.describe('Actions', () => {

await expect(page.locator('pre')).toHaveText('something went wrong');
});

test('submitting application/json should return http status code 415', async ({
baseURL,
page
}) => {
const response = await page.request.fetch(`${baseURL}/actions/form-errors`, {
method: 'POST',
body: JSON.stringify({ foo: 'bar' }),
headers: {
'Content-Type': 'application/json',
Origin: `${baseURL}`
}
});
const { type, error } = await response.json();
expect(type).toBe('error');
expect(error.message).toBe('Actions expect form-encoded data (received application/json)');
expect(response.status()).toBe(415);
});

test('submitting to a form action that does not exists, should return http status code 404', async ({
baseURL,
page
}) => {
const randomActionName = 'some-random-action';
const response = await page.request.fetch(`${baseURL}/actions/enhance?/${randomActionName}`, {
method: 'POST',
body: 'irrelevant',
headers: {
Origin: `${baseURL}`
}
});
const { type, error } = await response.json();
expect(type).toBe('error');
expect(error.message).toBe(`No action with name '${randomActionName}' found`);
expect(response.status()).toBe(404);
});
});

// Run in serial to not pollute the log with (correct) cookie warnings
Expand Down

0 comments on commit 86a1357

Please sign in to comment.