Browse Source

Task/improve error handling in HTML template middleware (#7331)

* Improve error handling

* Update changelog
pull/7340/head
Thomas Kaul 1 day ago
committed by GitHub
parent
commit
d35e76737b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 38
      apps/api/src/middlewares/html-template.middleware.ts

1
CHANGELOG.md

@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Resolved a startup error in data gathering caused by uninitialized data provider mappings
- Improved the error handling in the `HtmlTemplateMiddleware`
- Improved the error handling in the get quotes functionality of the _Financial Modeling Prep_ service
## 3.26.0 - 2026-07-14

38
apps/api/src/middlewares/html-template.middleware.ts

@ -97,20 +97,29 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
private indexHtmlMap: { [languageCode: string]: string } = {};
public constructor(private readonly i18nService: I18nService) {
try {
this.indexHtmlMap = SUPPORTED_LANGUAGE_CODES.reduce(
(map, languageCode) => ({
...map,
[languageCode]: readFileSync(
join(__dirname, '..', 'client', languageCode, 'index.html'),
'utf8'
)
}),
{}
);
} catch (error) {
this.logger.error('Failed to initialize index HTML map', error);
if (!environment.production) {
return;
}
this.indexHtmlMap = SUPPORTED_LANGUAGE_CODES.reduce((map, languageCode) => {
const indexHtmlPath = join(
__dirname,
'..',
'client',
languageCode,
'index.html'
);
try {
map[languageCode] = readFileSync(indexHtmlPath, 'utf8');
} catch {
this.logger.warn(
`Skipping language '${languageCode}': ${indexHtmlPath} not found`
);
}
return map;
}, {});
}
public use(request: Request, response: Response, next: NextFunction) {
@ -118,7 +127,8 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
let languageCode = path.substr(1, 2);
if (
!(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode)
!(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode) ||
!this.indexHtmlMap[languageCode]
) {
languageCode = DEFAULT_LANGUAGE_CODE;
}

Loading…
Cancel
Save