Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Abort infinite loop for preload errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkishi authored and pngwn committed May 17, 2019
1 parent 8653a79 commit d95b344
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions runtime/src/server/middleware/get_page_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export function get_page_handler(
const { server_routes, pages } = manifest;
const error_route = manifest.error;

function bail(req: Req, res: Res, err: Error) {
console.error(err);

const message = dev ? escape_html(err.message) : 'Internal server error';

res.statusCode = 500;
res.end(`<pre>${message}</pre>`);
}

function handle_error(req: Req, res: Res, statusCode: number, error: Error | string) {
handle_page({
pattern: null,
Expand Down Expand Up @@ -169,6 +178,10 @@ export function get_page_handler(

preloaded = await Promise.all(toPreload);
} catch (err) {
if (error) {
return bail(req, res, err)
}

preload_error = { statusCode: 500, message: err };
preloaded = []; // appease TypeScript
}
Expand Down Expand Up @@ -314,11 +327,8 @@ export function get_page_handler(
res.statusCode = status;
res.end(body);
} catch(err) {
console.log(err);
if (error) {
// we encountered an error while rendering the error page — oops
res.statusCode = 500;
res.end(`<pre>${escape_html(err.message)}</pre>`);
bail(req, res, err)
} else {
handle_error(req, res, 500, err);
}
Expand Down

0 comments on commit d95b344

Please sign in to comment.