Improve error handling for headers

This commit is contained in:
Iván Ovejero 2022-03-30 13:17:52 +02:00
parent fcd87affad
commit 8015f99211
2 changed files with 7 additions and 8 deletions

View file

@ -29,7 +29,7 @@
/* eslint-disable no-await-in-loop */
import * as express from 'express';
import { readFileSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import { readFile } from 'fs/promises';
import { cloneDeep } from 'lodash';
import { dirname as pathDirname, join as pathJoin, resolve as pathResolve } from 'path';
@ -1503,10 +1503,13 @@ class App {
async (req: express.Request, res: express.Response): Promise<object | void> => {
const packagesPath = pathJoin(__dirname, '..', '..', '..');
const headersPath = pathJoin(packagesPath, 'nodes-base', 'dist', 'nodes', 'headers');
if (!existsSync(`${headersPath}.js`)) return;
try {
return require(headersPath);
} catch (error) {
res.status(500).send('Failed to find headers file');
res.status(500).send('Failed to load headers file');
}
},
),

View file

@ -2742,12 +2742,8 @@ export default mixins(
await Promise.all(loadPromises);
if (this.defaultLocale !== 'en') {
try {
const headers = await this.restApi().getNodeTranslationHeaders();
addHeaders(headers, this.defaultLocale);
} catch (_) {
// no headers available
}
const headers = await this.restApi().getNodeTranslationHeaders();
if (headers) addHeaders(headers, this.defaultLocale);
}
} catch (error) {
this.$showError(