Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 unmatched URLs #99

Merged
merged 10 commits into from
Nov 26, 2024
2 changes: 2 additions & 0 deletions public/locales_euid/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"Enter your verification code": "Enter your verification code",
"Powered by": "Powered by",
"Internal Server Error": "Internal Server Error",
"Page Not Found": "Page Not Found",
"Unknown Error": "Unknown Error",
"euid-exit": "EXIT",
"Welcome!": "Hello,",
"Opt-Out": "Opt-Out",
Expand Down
2 changes: 2 additions & 0 deletions public/locales_uid2/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"Enter your verification code": "Enter your verification code",
"Powered by": "Powered by",
"Internal Server Error": "Internal Server Error",
"Page Not Found": "Page Not Found",
"Unknown Error": "Unknown Error",
"EXIT": "EXIT",
"Welcome!": "Hello,",
"Opt-Out": "Opt-Out",
Expand Down
2 changes: 2 additions & 0 deletions public/locales_uid2/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"Enter your verification code": "認証コードを入力してください",
"Powered by": "Powered by",
"Internal Server Error": "内部サーバーエラー",
"Page Not Found": "ページが見つかりません",
"Unknown Error": "不明なエラー",
"EXIT": "終了",
"Welcome!": "こんにちは",
"Opt-Out": "オプトアウト",
Expand Down
12 changes: 11 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ app.use((err: any, req: Request, res: Response, _next: NextFunction) => {

// render the error page
res.status(err.status || 500);
res.render('error');

let errorPageMessage;
if (err.status === 404) {
errorPageMessage = res.__('Page Not Found');
} else if (err.status === 500) {
errorPageMessage = res.__('Internal Server Error');
} else {
errorPageMessage = res.__('Unknown Error');
}

res.render('error', { errorPageMessage });
});

logger.log('info', `Using locales from ${LOCALE_FOLDER}`);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const handleEmailPromptSubmission: RequestHandler<{}, z.infer<typeof EmailPrompt
EmailPromptRequest.parse(req.body);
} catch (e) {
logger.log('error', 'error while parsing the request');
_next(createError(500));
_next(createError(400));
return;
}
const {
Expand Down Expand Up @@ -149,7 +149,7 @@ const defaultRouteHandler: RequestHandler<{}, {}, z.infer<typeof DefaultRouteReq
requestStep = DefaultRouteRequest.parse(req.body).step;
} catch (e) {
logger.log('error', 'error while parsing step');
next(createError(500));
next(createError(400));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion views_euid/error.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1>{{__ "Internal Server Error"}}</h1>
<h1> {{errorPageMessage}} </h1>
2 changes: 1 addition & 1 deletion views_uid2/error.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1>{{__ "Internal Server Error"}}</h1>
<h1> {{errorPageMessage}} </h1>