Browse Source

Improve error handling

pull/7331/head
Thomas Kaul 3 days ago
parent
commit
420ee15759
  1. 31
      apps/api/src/middlewares/html-template.middleware.ts

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

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

Loading…
Cancel
Save