Skip to content

Commit

Permalink
Merge pull request #99 from IABTechLab/ans-UID2-4477-return-404-unmat…
Browse files Browse the repository at this point in the history
…ched-requests

Return 404 unmatched URLs
  • Loading branch information
ashleysmithTTD authored Nov 26, 2024
2 parents 4fe78ee + 1b51435 commit c6096c6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
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>

0 comments on commit c6096c6

Please sign in to comment.