Skip to content

Commit 86a1357

Browse files
authored
fix: revert recent error changes (#11295)
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
1 parent b2b1951 commit 86a1357

File tree

3 files changed

+7
-39
lines changed

3 files changed

+7
-39
lines changed

.changeset/fast-radios-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: revert recent 'correctly return 415' and 'correctly return 404' changes

packages/kit/src/runtime/server/page/actions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,11 @@ async function call_action(event, actions) {
216216

217217
const action = actions[name];
218218
if (!action) {
219-
throw error(404, `No action with name '${name}' found`);
219+
throw new Error(`No action with name '${name}' found`);
220220
}
221221

222222
if (!is_form_content_type(event.request)) {
223-
throw error(
224-
415,
223+
throw new Error(
225224
`Actions expect form-encoded data (received ${event.request.headers.get('content-type')})`
226225
);
227226
}

packages/kit/test/apps/basics/test/test.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,42 +1242,6 @@ test.describe('Actions', () => {
12421242

12431243
await expect(page.locator('pre')).toHaveText('something went wrong');
12441244
});
1245-
1246-
test('submitting application/json should return http status code 415', async ({
1247-
baseURL,
1248-
page
1249-
}) => {
1250-
const response = await page.request.fetch(`${baseURL}/actions/form-errors`, {
1251-
method: 'POST',
1252-
body: JSON.stringify({ foo: 'bar' }),
1253-
headers: {
1254-
'Content-Type': 'application/json',
1255-
Origin: `${baseURL}`
1256-
}
1257-
});
1258-
const { type, error } = await response.json();
1259-
expect(type).toBe('error');
1260-
expect(error.message).toBe('Actions expect form-encoded data (received application/json)');
1261-
expect(response.status()).toBe(415);
1262-
});
1263-
1264-
test('submitting to a form action that does not exists, should return http status code 404', async ({
1265-
baseURL,
1266-
page
1267-
}) => {
1268-
const randomActionName = 'some-random-action';
1269-
const response = await page.request.fetch(`${baseURL}/actions/enhance?/${randomActionName}`, {
1270-
method: 'POST',
1271-
body: 'irrelevant',
1272-
headers: {
1273-
Origin: `${baseURL}`
1274-
}
1275-
});
1276-
const { type, error } = await response.json();
1277-
expect(type).toBe('error');
1278-
expect(error.message).toBe(`No action with name '${randomActionName}' found`);
1279-
expect(response.status()).toBe(404);
1280-
});
12811245
});
12821246

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

0 commit comments

Comments
 (0)