{"record":{"id":"1eec47016b735560","repo":"withastro/astro","slug":"unsupported-media-type","errorCode":"UNSUPPORTED_MEDIA_TYPE","errorMessage":"This action only accepts FormData.","messagePattern":"This action only accepts FormData\\.","errorType":"error_code","errorClass":"ActionError","httpStatus":415,"severity":"error","filePath":"packages/astro/src/actions/runtime/server.ts","lineNumber":80,"sourceCode":"\tObject.assign(safeServerHandler, {\n\t\torThrow(this: ActionAPIContext, unparsedInput: unknown) {\n\t\t\tif (typeof this === 'function') {\n\t\t\t\tthrow new AstroError(ActionCalledFromServerError);\n\t\t\t}\n\t\t\treturn serverHandler(unparsedInput, this);\n\t\t},\n\t});\n\n\treturn safeServerHandler as ActionClient<TOutput, TAccept, TInputSchema> & string;\n}\n\nfunction getFormServerHandler<TOutput, TInputSchema extends z.$ZodType>(\n\thandler: ActionHandler<TInputSchema, TOutput>,\n\tinputSchema?: TInputSchema,\n) {\n\treturn async (unparsedInput: unknown, context: ActionAPIContext): Promise<Awaited<TOutput>> => {\n\t\tif (!(unparsedInput instanceof FormData)) {\n\t\t\tthrow new ActionError({\n\t\t\t\tcode: 'UNSUPPORTED_MEDIA_TYPE',\n\t\t\t\tmessage: 'This action only accepts FormData.',\n\t\t\t});\n\t\t}\n\n\t\tif (!inputSchema) return await handler(unparsedInput, context);\n\n\t\tconst parsed = await parseFormInput(inputSchema, unparsedInput);\n\n\t\tif (!parsed.success) {\n\t\t\tthrow new ActionInputError(parsed.error.issues);\n\t\t}\n\t\treturn await handler(parsed.data, context);\n\t};\n}\n\nasync function parseFormInput(inputSchema: z.$ZodType, unparsedInput: FormData) {\n\tconst baseSchema = unwrapBaseZ4ObjectSchema(inputSchema, unparsedInput);","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/actions/runtime/server.ts#L62-L98","documentation":"The action was defined with accept: 'form', so its server handler (getFormServerHandler) requires the input to be a FormData instance. Receiving any other value (plain object, JSON) throws ActionError code UNSUPPORTED_MEDIA_TYPE (HTTP 415).","triggerScenarios":"A form-accept action invoked via RPC/JSON (e.g. actions.myForm({ email }) with a plain object from the client), or called programmatically on the server with a non-FormData value.","commonSituations":"Declaring an action as form-only but calling it like a normal JSON action from client code; unit-testing the action with a plain object instead of FormData.","solutions":["Call the action with a real FormData object (e.g. new FormData(formElement)).","If you want JSON/RPC calls, remove accept: 'form' or add a separate JSON action.","Use an HTML <form> posting to the action for the form-accept path."],"exampleFix":"// before\nexport const subscribe = defineAction({\n  accept: 'form',\n  input: z.object({ email: z.string().email() }),\n  handler: async (i) => i,\n});\n// caller\nawait actions.subscribe({ email: 'a@b.c' }); // throws 415\n// after\nconst fd = new FormData();\nfd.set('email', 'a@b.c');\nawait actions.subscribe(fd);","handlingStrategy":"type-guard","validationCode":"// Ensure the value is FormData before calling a form-accept action.\nif (!(payload instanceof FormData)) {\n  throw new Error('This action requires a FormData instance; use accept:\"form\".');\n}","typeGuard":"function isFormData(v: unknown): v is FormData {\n  return typeof FormData !== 'undefined' && v instanceof FormData;\n}","tryCatchPattern":"try {\n  await actions.subscribe(payload);\n} catch (e) {\n  if (e instanceof ActionError && e.code === 'UNSUPPORTED_MEDIA_TYPE') {\n    // build a FormData and retry, or guide the user to use a form\n  } else throw e;\n}","preventionTips":["Match call style to the action's accept mode (FormData for 'form', objects for JSON).","Build FormData from the form element with new FormData(formEl).","Keep a single action either form- or JSON-accepting to avoid mismatch."],"tags":["actions","form-data","validation","http-415"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}