File tree Expand file tree Collapse file tree 3 files changed +7
-39
lines changed
Expand file tree Collapse file tree 3 files changed +7
-39
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sveltejs/kit ' : patch
3+ ---
4+
5+ fix: revert recent 'correctly return 415' and 'correctly return 404' changes
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments