Skip to content

Commit 0464283

Browse files
authored
chore: specify the route ID in the error message during development when making a form action request to a route without form actions (#13167)
closes #11876
1 parent 88ab109 commit 0464283

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.changeset/ninety-taxis-bathe.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+
chore: specify the route ID in the error message during development when making a form action request to a route without form actions

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as devalue from 'devalue';
2+
import { DEV } from 'esm-env';
23
import { json } from '../../../exports/index.js';
34
import { get_status, normalize_error } from '../../../utils/error.js';
45
import { is_form_content_type, negotiate } from '../../../utils/http.js';
@@ -27,8 +28,9 @@ export async function handle_action_json_request(event, options, server) {
2728
const no_actions_error = new SvelteKitError(
2829
405,
2930
'Method Not Allowed',
30-
'POST method not allowed. No actions exist for this page'
31+
`POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}`
3132
);
33+
3234
return action_json(
3335
{
3436
type: 'error',
@@ -153,7 +155,7 @@ export async function handle_action_request(event, server) {
153155
error: new SvelteKitError(
154156
405,
155157
'Method Not Allowed',
156-
'POST method not allowed. No actions exist for this page'
158+
`POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}`
157159
)
158160
};
159161
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ test.describe('Errors', () => {
373373
expect(await res_json.json()).toEqual({
374374
type: 'error',
375375
error: {
376-
message: 'POST method not allowed. No actions exist for this page (405 Method Not Allowed)'
376+
message: process.env.DEV
377+
? 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (405 Method Not Allowed)'
378+
: 'POST method not allowed. No form actions exist for this page (405 Method Not Allowed)'
377379
}
378380
});
379381
});

0 commit comments

Comments
 (0)