diff --git a/.changeset/ninety-taxis-bathe.md b/.changeset/ninety-taxis-bathe.md new file mode 100644 index 000000000000..1136fa17f096 --- /dev/null +++ b/.changeset/ninety-taxis-bathe.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: specify the route ID in the error message during development when making a form action request to a route without form actions diff --git a/packages/kit/src/runtime/server/page/actions.js b/packages/kit/src/runtime/server/page/actions.js index ed37c3e18a70..6fd2cea38f40 100644 --- a/packages/kit/src/runtime/server/page/actions.js +++ b/packages/kit/src/runtime/server/page/actions.js @@ -1,4 +1,5 @@ import * as devalue from 'devalue'; +import { DEV } from 'esm-env'; import { json } from '../../../exports/index.js'; import { get_status, normalize_error } from '../../../utils/error.js'; import { is_form_content_type, negotiate } from '../../../utils/http.js'; @@ -27,8 +28,9 @@ export async function handle_action_json_request(event, options, server) { const no_actions_error = new SvelteKitError( 405, 'Method Not Allowed', - 'POST method not allowed. No actions exist for this page' + `POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}` ); + return action_json( { type: 'error', @@ -153,7 +155,7 @@ export async function handle_action_request(event, server) { error: new SvelteKitError( 405, 'Method Not Allowed', - 'POST method not allowed. No actions exist for this page' + `POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}` ) }; } diff --git a/packages/kit/test/apps/basics/test/server.test.js b/packages/kit/test/apps/basics/test/server.test.js index 3c57fc9904c2..28fdc180b3c1 100644 --- a/packages/kit/test/apps/basics/test/server.test.js +++ b/packages/kit/test/apps/basics/test/server.test.js @@ -373,7 +373,9 @@ test.describe('Errors', () => { expect(await res_json.json()).toEqual({ type: 'error', error: { - message: 'POST method not allowed. No actions exist for this page (405 Method Not Allowed)' + message: process.env.DEV + ? 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (405 Method Not Allowed)' + : 'POST method not allowed. No form actions exist for this page (405 Method Not Allowed)' } }); });