0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

[ci] format

This commit is contained in:
lilnasy 2023-10-18 13:33:55 +00:00 committed by astrobot-houston
parent ad2bb91559
commit a44a7a9809
2 changed files with 12 additions and 5 deletions

View file

@ -43,7 +43,7 @@ export interface RenderErrorOptions {
status: 404 | 500; status: 404 | 500;
/** /**
* Whether to skip onRequest() while rendering the error page. Defaults to false. * Whether to skip onRequest() while rendering the error page. Defaults to false.
*/ */
skipMiddleware?: boolean; 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). * 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 * 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 errorRouteData = matchRoute('/' + status, this.#manifestData);
const url = new URL(request.url); const url = new URL(request.url);
if (errorRouteData) { if (errorRouteData) {
@ -296,7 +299,11 @@ export class App {
} catch { } catch {
// Middleware may be the cause of the error, so we try rendering 404/500.astro without it. // Middleware may be the cause of the error, so we try rendering 404/500.astro without it.
if (skipMiddleware === false && mod.onRequest) { if (skipMiddleware === false && mod.onRequest) {
return this.#renderError(request, { status, response: originalResponse, skipMiddleware: true }); return this.#renderError(request, {
status,
response: originalResponse,
skipMiddleware: true,
});
} }
} }
} }

View file

@ -222,12 +222,12 @@ describe('Middleware API in PROD mode, SSR', () => {
it('should render 500.astro when the middleware throws an error', async () => { it('should render 500.astro when the middleware throws an error', async () => {
const request = new Request('http://example.com/throw'); const request = new Request('http://example.com/throw');
const routeData = app.match(request, { matchNotFound: true }); const routeData = app.match(request, { matchNotFound: true });
const response = await app.render(request, routeData); const response = await app.render(request, routeData);
expect(response).to.deep.include({ status: 500 }); expect(response).to.deep.include({ status: 500 });
const text = await response.text(); 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 () => { it('the integration should receive the path to the middleware', async () => {