File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sveltejs/kit ' : patch
3+ ---
4+
5+ fix: correctly return 404 when a form action is not found
Original file line number Diff line number Diff line change @@ -216,7 +216,7 @@ async function call_action(event, actions) {
216216
217217 const action = actions [ name ] ;
218218 if ( ! action ) {
219- throw new Error ( `No action with name '${ name } ' found` ) ;
219+ throw error ( 404 , `No action with name '${ name } ' found` ) ;
220220 }
221221
222222 if ( ! is_form_content_type ( event . request ) ) {
Original file line number Diff line number Diff line change @@ -1260,6 +1260,24 @@ test.describe('Actions', () => {
12601260 expect ( error . message ) . toBe ( 'Actions expect form-encoded data (received application/json)' ) ;
12611261 expect ( response . status ( ) ) . toBe ( 415 ) ;
12621262 } ) ;
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+ } ) ;
12631281} ) ;
12641282
12651283// Run in serial to not pollute the log with (correct) cookie warnings
You can’t perform that action at this time.
0 commit comments