From 3ae31a86d514e439183b31e2995c739034a0f6bf Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Mon, 16 Dec 2024 15:04:19 +0800 Subject: [PATCH 1/5] better error message? --- packages/kit/src/runtime/server/page/actions.js | 6 ++++-- packages/kit/test/apps/basics/test/server.test.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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..1531c295cf90 100644 --- a/packages/kit/test/apps/basics/test/server.test.js +++ b/packages/kit/test/apps/basics/test/server.test.js @@ -373,7 +373,7 @@ 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: 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (405 Method Not Allowed)' } }); }); From ab117a5574a1dd16f5cc8e5bc6b2006c6eadc133 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Mon, 16 Dec 2024 15:06:17 +0800 Subject: [PATCH 2/5] changeset --- .changeset/ninety-taxis-bathe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ninety-taxis-bathe.md diff --git a/.changeset/ninety-taxis-bathe.md b/.changeset/ninety-taxis-bathe.md new file mode 100644 index 000000000000..5065534552f4 --- /dev/null +++ b/.changeset/ninety-taxis-bathe.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: improve error message when making a form action request to a route without form actions From 938a32eb8fedfd7f1d75ac212a64bb765b80838e Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Mon, 16 Dec 2024 15:11:43 +0800 Subject: [PATCH 3/5] changeset message --- .changeset/ninety-taxis-bathe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/ninety-taxis-bathe.md b/.changeset/ninety-taxis-bathe.md index 5065534552f4..1136fa17f096 100644 --- a/.changeset/ninety-taxis-bathe.md +++ b/.changeset/ninety-taxis-bathe.md @@ -2,4 +2,4 @@ '@sveltejs/kit': patch --- -chore: improve error message when making a form action request to a route without form actions +chore: specify the route ID in the error message during development when making a form action request to a route without form actions From d70161efd0b642e2c5d85917d2eaecac025241a7 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Mon, 16 Dec 2024 15:14:19 +0800 Subject: [PATCH 4/5] format --- packages/kit/test/apps/basics/test/server.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kit/test/apps/basics/test/server.test.js b/packages/kit/test/apps/basics/test/server.test.js index 1531c295cf90..44e132bc2415 100644 --- a/packages/kit/test/apps/basics/test/server.test.js +++ b/packages/kit/test/apps/basics/test/server.test.js @@ -373,7 +373,8 @@ test.describe('Errors', () => { expect(await res_json.json()).toEqual({ type: 'error', error: { - message: 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (405 Method Not Allowed)' + message: + 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (405 Method Not Allowed)' } }); }); From 5d93270e4aa7bfa5f839f4d5b623d514a43a774a Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Mon, 16 Dec 2024 15:26:24 +0800 Subject: [PATCH 5/5] fix test --- packages/kit/test/apps/basics/test/server.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/kit/test/apps/basics/test/server.test.js b/packages/kit/test/apps/basics/test/server.test.js index 44e132bc2415..28fdc180b3c1 100644 --- a/packages/kit/test/apps/basics/test/server.test.js +++ b/packages/kit/test/apps/basics/test/server.test.js @@ -373,8 +373,9 @@ test.describe('Errors', () => { expect(await res_json.json()).toEqual({ type: 'error', error: { - message: - 'POST method not allowed. No form actions exist for the page at /errors/missing-actions (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)' } }); });