From f69526c1409b6869e761822a7af8237ccdb766bf Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 5 Nov 2020 12:45:02 +1300 Subject: [PATCH] Fixed error logged for absent redirects config refs #11085 - Incorrect usage error was logged to the output when there was no recirecst configuration file present in the system. Previously an empty string was returned in such situation, resulting in "ENOENT" error, which was ignored through special handling. - The fix resembles logic in redirects async getter function where empty array is returned when the config file does not exits. - Attempting to read unexistent config should not ever happen and will be handled on the config service layer, this is why special "ENOENT" handling has been removed --- core/frontend/services/redirects/settings.js | 5 +++++ core/server/web/shared/middlewares/custom-redirects.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/frontend/services/redirects/settings.js b/core/frontend/services/redirects/settings.js index 4f04a55d91..59c9a88415 100644 --- a/core/frontend/services/redirects/settings.js +++ b/core/frontend/services/redirects/settings.js @@ -191,6 +191,11 @@ const get = () => { const loadRedirectsFile = () => { const filePath = getCurrentRedirectsFilePathSync(); + + if (filePath === null) { + return defaultJsonFileContent; + } + const content = fs.readFileSync(filePath); return parseRedirectsFile(content, path.extname(filePath)); diff --git a/core/server/web/shared/middlewares/custom-redirects.js b/core/server/web/shared/middlewares/custom-redirects.js index 2020da4753..1bb95964fd 100644 --- a/core/server/web/shared/middlewares/custom-redirects.js +++ b/core/server/web/shared/middlewares/custom-redirects.js @@ -75,7 +75,7 @@ _private.registerRoutes = () => { } catch (err) { if (errors.utils.isIgnitionError(err)) { logging.error(err); - } else if (err.code !== 'ENOENT') { + } else { logging.error(new errors.IncorrectUsageError({ message: i18n.t('errors.middleware.redirects.register'), context: err.message,