From deef1bbfcfe16b1b56f4a9a2d996d2bf1459ddef Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 16 Aug 2018 12:25:23 -0400 Subject: [PATCH] handle unknown preload errors --- src/middleware.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 027c57a..cd3bf94 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -299,13 +299,10 @@ function get_page_handler( parts: [ { name: null, component: error_route } ] - }, req, res, statusCode, error); + }, req, res, statusCode, error || new Error('Unknown error in preload function')); } function handle_page(page: Page, req: Req, res: ServerResponse, status = 200, error: Error | string = null) { - const get_params = page.parts[page.parts.length - 1].params || (() => ({})); - const match = error ? null : page.pattern.exec(req.path); - const chunks: Record = get_chunks(); res.setHeader('Content-Type', 'text/html'); @@ -391,6 +388,8 @@ function get_page_handler( }) : {}; + const match = error ? null : page.pattern.exec(req.path); + Promise.all([root_preloaded].concat(page.parts.map(part => { if (!part) return null;