Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Task/improve error handling in HTML template middleware (#7331)
Thomas Kauld35e76737b1c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e218513b7c..1e6176b264 100644--- a/CHANGELOG.md+++ b/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-14diff --git a/apps/api/src/middlewares/html-template.middleware.ts b/apps/api/src/middlewares/html-template.middleware.tsindex 325f64eaad..bdace34024 100644--- a/apps/api/src/middlewares/html-template.middleware.ts+++ b/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;}