Skip to content

Commit

Permalink
changes to not hardcode internal server error
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Nov 25, 2024
1 parent 706cac5 commit fe4bd2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 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
16 changes: 15 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.use(helmet());
app.use(i18n.init);
app.use((req, _res, next) => {
const locale = req.acceptsLanguages()[0] || LanguagesUID2.English;
console.log(locale)

Check warning on line 48 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 48 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

Check warning on line 48 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 48 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
i18n.setLocale(locale);
next();
});
Expand Down Expand Up @@ -75,7 +76,19 @@ 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")

Check failure on line 82 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 82 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

Check failure on line 82 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 82 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
}

Check failure on line 83 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 83 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 83 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 83 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (err.status === 500) {
errorPageMessage = res.__("Internal Server Error")

Check failure on line 85 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 85 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

Check failure on line 85 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 85 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
}

Check failure on line 86 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 86 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 86 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block

Check failure on line 86 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
errorPageMessage = res.__("Unknown Error")

Check failure on line 88 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 88 in src/app.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
}

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

logger.log('info', `Using locales from ${LOCALE_FOLDER}`);
Expand All @@ -100,6 +113,7 @@ Handlebars.registerHelper('__n', (s, count) => {
return i18n.__n(s, count);
});


Handlebars.registerPartials(layoutPath);

export default app;
4 changes: 3 additions & 1 deletion views_uid2/error.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<h1>{{__ "Internal Server Error"}}</h1>
<h1>
{{errorPageMessage}}
</h1>

0 comments on commit fe4bd2d

Please sign in to comment.