Skip to content

Commit 24cda24

Browse files
committed
Update comments
Update the first comment to better explain the purpose of this code block, which only serves very specific routes such as '/charon/invalid'. The nested comment was also not entirely accurate, as Next.js can respond with 404 for some routes. I lifted it out and rewrote as a proper TODO based on the linked issues.
1 parent 17542a4 commit 24cda24

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/routing/errors.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,23 @@ export async function setup(app) {
116116
.end();
117117
}
118118

119-
/* Delegate to Next.js only for GET and HEAD requests. This aligns with
120-
* handling in src/routing/staticSite.js.
119+
/* Delegate to Next.js for 404s that originate from Express routes.
120+
* Because Express routes take priority over the Next.js catch-all in
121+
* src/routing/staticSite.js, a 404 in an Express route would not render
122+
* with the typical site layout we explicitly hand it back to Next.js here.
123+
* Note that this is only for GET and HEAD requests to align with handling
124+
* in src/routing/staticSite.js.
121125
*/
122126
if (err instanceof NotFound && ["GET", "HEAD"].includes(req.method)) {
123-
/* A note about routing: if the current URL path (i.e. req.path) matches a
124-
* a page known to the NextJS routes ("pages") then that page will be
125-
* shown (with response code 200). Moving to server-side rendering of
126-
* NotFound errors (and InternalServerError etc) will not only solve this
127-
* but will also allow us to provide information about the error. See the
128-
* following issues for more:
129-
* <https://github.com/nextstrain/nextstrain.org/issues/774>
130-
* <https://github.com/nextstrain/nextstrain.org/issues/518>
131-
*/
132127
return await endpoints.nextJsApp.handleRequest(req, res);
133128
}
134129

130+
/* TODO: Serve custom error pages for user errors such as BadRequest¹ and
131+
* Forbidden²
132+
* ¹ <https://github.com/nextstrain/nextstrain.org/issues/774>
133+
* ² <https://github.com/nextstrain/nextstrain.org/issues/518>
134+
*/
135+
135136
utils.verbose(`Sending ${err} error as HTML with custom error handler`);
136137
return finalhandler(req, res, { onerror })(err);
137138
});

0 commit comments

Comments
 (0)