summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/core/app/index.ts13
-rw-r--r--packages/astro/test/middleware.test.js4
2 files changed, 12 insertions, 5 deletions
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts
index 6475718ac..b6bf838a9 100644
--- a/packages/astro/src/core/app/index.ts
+++ b/packages/astro/src/core/app/index.ts
@@ -43,7 +43,7 @@ export interface RenderErrorOptions {
status: 404 | 500;
/**
* Whether to skip onRequest() while rendering the error page. Defaults to false.
- */
+ */
skipMiddleware?: boolean;
}
@@ -256,7 +256,10 @@ export class App {
* If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
* This also handles pre-rendered /404 or /500 routes
*/
- async #renderError(request: Request, { status, response: originalResponse, skipMiddleware = false }: RenderErrorOptions): Promise<Response> {
+ async #renderError(
+ request: Request,
+ { status, response: originalResponse, skipMiddleware = false }: RenderErrorOptions
+ ): Promise<Response> {
const errorRouteData = matchRoute('/' + status, this.#manifestData);
const url = new URL(request.url);
if (errorRouteData) {
@@ -296,7 +299,11 @@ export class App {
} catch {
// Middleware may be the cause of the error, so we try rendering 404/500.astro without it.
if (skipMiddleware === false && mod.onRequest) {
- return this.#renderError(request, { status, response: originalResponse, skipMiddleware: true });
+ return this.#renderError(request, {
+ status,
+ response: originalResponse,
+ skipMiddleware: true,
+ });
}
}
}
diff --git a/packages/astro/test/middleware.test.js b/packages/astro/test/middleware.test.js
index b882fcc84..66abce3b8 100644
--- a/packages/astro/test/middleware.test.js
+++ b/packages/astro/test/middleware.test.js
@@ -222,12 +222,12 @@ describe('Middleware API in PROD mode, SSR', () => {
it('should render 500.astro when the middleware throws an error', async () => {
const request = new Request('http://example.com/throw');
const routeData = app.match(request, { matchNotFound: true });
-
+
const response = await app.render(request, routeData);
expect(response).to.deep.include({ status: 500 });
const text = await response.text();
- expect(text).to.include("<h1>There was an error rendering the page.</h1>")
+ expect(text).to.include('<h1>There was an error rendering the page.</h1>');
});
it('the integration should receive the path to the middleware', async () => {