Home / Function/ renderError() — astro Function Reference

renderError() — astro Function Reference

Architecture documentation for the renderError() function in app.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  5d858b84_f88b_316b_3874_cf1a5d8a7829["renderError()"]
  df0b0a04_8315_c9cf_d541_013f247434eb["AstroServerApp"]
  5d858b84_f88b_316b_3874_cf1a5d8a7829 -->|defined in| df0b0a04_8315_c9cf_d541_013f247434eb
  665f578e_0fb9_ef8e_c5d0_8499da416b76["createRenderContext()"]
  5d858b84_f88b_316b_3874_cf1a5d8a7829 -->|calls| 665f578e_0fb9_ef8e_c5d0_8499da416b76
  style 5d858b84_f88b_316b_3874_cf1a5d8a7829 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/vite-plugin-app/app.ts lines 226–291

	async renderError(
		request: Request,
		{ locals, skipMiddleware = false, error, clientAddress, status }: RenderErrorOptions,
	): Promise<Response> {
		// we always throw when we have Astro errors around the middleware
		if (
			isAstroError(error) &&
			[MiddlewareNoDataOrNextCalled.name, MiddlewareNotAResponse.name].includes(error.name)
		) {
			throw error;
		}

		const renderRoute = async (routeData: RouteData) => {
			try {
				const preloadedComponent = await this.pipeline.getComponentByRoute(routeData);
				const renderContext = await this.createRenderContext({
					locals,
					pipeline: this.pipeline,
					pathname: await this.getPathnameFromRequest(request),
					skipMiddleware,
					request,
					routeData,
					clientAddress,
					status,
					shouldInjectCspMetaTags: !!this.manifest.csp,
				});
				renderContext.props.error = error;
				const response = await renderContext.render(preloadedComponent);

				if (error) {
					// Log useful information that the custom 500 page may not display unlike the default error overlay
					this.logger.error('router', (error as AstroError).stack || (error as AstroError).message);
				}

				return response;
			} catch (_err) {
				if (skipMiddleware === false) {
					return this.renderError(request, {
						clientAddress: undefined,
						prerenderedErrorPageFetch: fetch,
						status: 500,
						skipMiddleware: true,
						error: _err,
					});
				}
				// If even skipping the middleware isn't enough to prevent the error, show the dev overlay
				throw _err;
			}
		};

		if (status === 404) {
			const custom404 = getCustom404Route(this.manifestData);
			if (custom404) {
				return renderRoute(custom404);
			}
		}

		const custom500 = getCustom500Route(this.manifestData);

		// Show dev overlay
		if (!custom500) {
			throw error;
		} else {
			return renderRoute(custom500);
		}
	}

Domain

Subdomains

Frequently Asked Questions

What does renderError() do?
renderError() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-app/app.ts.
Where is renderError() defined?
renderError() is defined in packages/astro/src/vite-plugin-app/app.ts at line 226.
What does renderError() call?
renderError() calls 1 function(s): createRenderContext.

Analyze Your Own Codebase

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

Try Supermodel Free