From b4c5739876870858c13e3f5cd83b2affde9edce7 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Tue, 16 Nov 2021 01:04:21 +0000 Subject: [PATCH] [Branding] prevent logging when config not set Out of the box, the rendering service will check the config and see the default value and log an info message saying that the branding config is invalid or not set. Everytime you refresh the browser you will get those log messages. This sets it to only log error messages if the user sets the branding config and it is invalid. Signed-off-by: Kawika Avilla --- .../server/rendering/rendering_service.test.ts | 5 +++++ src/core/server/rendering/rendering_service.tsx | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/server/rendering/rendering_service.test.ts b/src/core/server/rendering/rendering_service.test.ts index 61a7f0ce3dea..e4d52dc13648 100644 --- a/src/core/server/rendering/rendering_service.test.ts +++ b/src/core/server/rendering/rendering_service.test.ts @@ -163,6 +163,11 @@ describe('RenderingService', () => { const result = await service.isUrlValid('http://notfound.svg', 'config'); expect(result).toEqual(false); }); + + it('checks default URL returns false', async () => { + const result = await service.isUrlValid('/', 'config'); + expect(result).toEqual(false); + }); }); describe('isTitleValid()', () => { diff --git a/src/core/server/rendering/rendering_service.tsx b/src/core/server/rendering/rendering_service.tsx index efaab2b94947..38e134cfb486 100644 --- a/src/core/server/rendering/rendering_service.tsx +++ b/src/core/server/rendering/rendering_service.tsx @@ -315,8 +315,11 @@ export class RenderingService { * @returns {boolean} indicate if the URL is valid/invalid */ public isUrlValid = async (url: string, configName?: string): Promise => { + if (url === '/') { + return false; + } if (url.match(/\.(png|svg|gif|PNG|SVG|GIF)$/) === null) { - this.logger.get('branding').info(configName + ' config is not found or invalid.'); + this.logger.get('branding').error(`${configName} config is invalid.`); return false; } return await Axios.get(url, { adapter: AxiosHttpAdapter, maxRedirects: 0 }) @@ -324,7 +327,7 @@ export class RenderingService { return true; }) .catch(() => { - this.logger.get('branding').info(configName + ' config is not found or invalid'); + this.logger.get('branding').error(`${configName} URL was not found or invalid.`); return false; }); }; @@ -338,12 +341,14 @@ export class RenderingService { * @returns {boolean} indicate if user input title is valid/invalid */ public isTitleValid = (title: string, configName?: string): boolean => { - if (!title || title.length > 36) { + if (!title) { + return false; + } + if (title.length > 36) { this.logger .get('branding') - .info( - configName + - ' config is not found or invalid. Title length should be between 1 to 36 characters.' + .error( + `${configName} config is not found or invalid. Title length should be between 1 to 36 characters.` ); return false; }