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
  84b4e3d3_9059_983c_2845_94bc19dd377b["renderError()"]
  ec09edcb_7ea1_1684_bf75_6f5bf722dd9c["DevApp"]
  84b4e3d3_9059_983c_2845_94bc19dd377b -->|defined in| ec09edcb_7ea1_1684_bf75_6f5bf722dd9c
  8c958a17_30f5_1678_b38a_5d51a320ab3f["createRenderContext()"]
  84b4e3d3_9059_983c_2845_94bc19dd377b -->|calls| 8c958a17_30f5_1678_b38a_5d51a320ab3f
  style 84b4e3d3_9059_983c_2845_94bc19dd377b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/app/dev/app.ts lines 71–136

	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: false,
				});
				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/core/app/dev/app.ts.
Where is renderError() defined?
renderError() is defined in packages/astro/src/core/app/dev/app.ts at line 71.
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