Skip to content

Commit

Permalink
avoid extra variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy committed Oct 13, 2023
1 parent 5f9fe62 commit c2e3642
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ export class App {
return this.#mergeResponses(response, originalResponse, override);
}
const mod = await this.#getModuleForRoute(errorRouteData);
let usedMiddleware = false;
try {
const newRenderContext = await this.#createRenderContext(
url,
Expand All @@ -284,16 +283,16 @@ export class App {
const page = (await mod.page()) as any;
if (runMiddleware && mod.onRequest) {
this.#pipeline.setMiddlewareFunction(mod.onRequest as MiddlewareEndpointHandler);
usedMiddleware = true;
}
if (!runMiddleware) {
// make sure middleware set by other requests is cleared out
this.#pipeline.unsetMiddlewareFunction();
}
const response = await this.#pipeline.renderRoute(newRenderContext, page);
return this.#mergeResponses(response, originalResponse);
} catch {
// Middleware may be the cause of the error, so we try rendering 404/500.astro without it.
if (runMiddleware && usedMiddleware) {
if (runMiddleware && mod.onRequest) {
return this.#renderError(request, { status, response: originalResponse, runMiddleware: false });
}
}
Expand Down

0 comments on commit c2e3642

Please sign in to comment.