Home / Function/ actions.handleAction() — astro Function Reference

actions.handleAction() — astro Function Reference

Architecture documentation for the actions.handleAction() function in client.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  029ae83e_a6a8_f719_9d51_5180774e412b["actions.handleAction()"]
  de871608_3ba9_f938_cdef_8bded16fa30e["client.ts"]
  029ae83e_a6a8_f719_9d51_5180774e412b -->|defined in| de871608_3ba9_f938_cdef_8bded16fa30e
  style 029ae83e_a6a8_f719_9d51_5180774e412b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/actions/runtime/entrypoints/client.ts lines 41–98

	handleAction: async (param, path) => {
		const headers = new Headers();
		headers.set('Accept', 'application/json');
		// Apply adapter-specific headers for internal fetches
		for (const [key, value] of Object.entries(internalFetchHeaders)) {
			headers.set(key, value);
		}
		let body = param;
		if (!(body instanceof FormData)) {
			try {
				body = JSON.stringify(param);
			} catch (e) {
				throw new ActionError({
					code: 'BAD_REQUEST',
					message: `Failed to serialize request body to JSON. Full error: ${(e as Error).message}`,
				});
			}
			if (body) {
				headers.set('Content-Type', 'application/json');
			} else {
				headers.set('Content-Length', '0');
			}
		}
		const rawResult = await fetch(
			getActionPathFromString({
				baseUrl: import.meta.env.BASE_URL,
				shouldAppendTrailingSlash,
				path: getActionQueryString(path),
			}),
			{
				method: 'POST',
				body,
				headers,
			},
		);

		if (rawResult.status === 204) {
			return deserializeActionResult({ type: 'empty', status: 204 });
		}

		const bodyText = await rawResult.text();

		if (rawResult.ok) {
			return deserializeActionResult({
				type: 'data',
				body: bodyText,
				status: 200,
				contentType: 'application/json+devalue',
			});
		}

		return deserializeActionResult({
			type: 'error',
			body: bodyText,
			status: rawResult.status,
			contentType: 'application/json',
		});
	},

Domain

Subdomains

Frequently Asked Questions

What does actions.handleAction() do?
actions.handleAction() is a function in the astro codebase, defined in packages/astro/src/actions/runtime/entrypoints/client.ts.
Where is actions.handleAction() defined?
actions.handleAction() is defined in packages/astro/src/actions/runtime/entrypoints/client.ts at line 41.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free