diff --git a/.changeset/fast-radios-tell.md b/.changeset/fast-radios-tell.md new file mode 100644 index 000000000000..a8873b19b8d3 --- /dev/null +++ b/.changeset/fast-radios-tell.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: revert recent 'correctly return 415' and 'correctly return 404' changes diff --git a/packages/kit/src/runtime/server/page/actions.js b/packages/kit/src/runtime/server/page/actions.js index 42b0e7d11b19..0d656815d83d 100644 --- a/packages/kit/src/runtime/server/page/actions.js +++ b/packages/kit/src/runtime/server/page/actions.js @@ -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')})` ); } diff --git a/packages/kit/test/apps/basics/test/test.js b/packages/kit/test/apps/basics/test/test.js index 6ad47289af0d..ef87a33f2185 100644 --- a/packages/kit/test/apps/basics/test/test.js +++ b/packages/kit/test/apps/basics/test/test.js @@ -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