diff --git a/packages/actions/src/runtime/route.ts b/packages/actions/src/runtime/route.ts index 068203a7bb..73c72f391d 100644 --- a/packages/actions/src/runtime/route.ts +++ b/packages/actions/src/runtime/route.ts @@ -10,13 +10,14 @@ export const POST: APIRoute = async (context) => { const actionPathKeys = url.pathname.replace('/_actions/', '').split('.'); const action = await getAction(actionPathKeys); const contentType = request.headers.get('Content-Type'); - let args: any; - if (contentType === 'application/json') { - args = await request.clone().json(); - } - if (formContentTypes.some((f) => contentType?.startsWith(f))) { - args = await request.clone().formData(); + if (contentType !== 'application/json') { + throw new ActionError({ + status: 'INTERNAL_SERVER_ERROR', + message: + 'Called an action with a non-JSON body. To enhance an action to accept form data, add `enhance: true` to your `defineAction()` config.', + }); } + const args = await request.clone().json(); let result: unknown; try { result = await ApiContextStorage.run(context, () => action(args));