Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy authored and astrobot-houston committed Oct 18, 2023
1 parent ad2bb91 commit a44a7a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface RenderErrorOptions {
status: 404 | 500;
/**
* Whether to skip onRequest() while rendering the error page. Defaults to false.
*/
*/
skipMiddleware?: boolean;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit a44a7a9

Please sign in to comment.