Skip to content

Commit

Permalink
[Branding] prevent logging when config not set
Browse files Browse the repository at this point in the history
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 <kavilla414@gmail.com>
  • Loading branch information
kavilla committed Nov 16, 2021
1 parent ff84b35 commit b4c5739
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/core/server/rendering/rendering_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
17 changes: 11 additions & 6 deletions src/core/server/rendering/rendering_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,19 @@ export class RenderingService {
* @returns {boolean} indicate if the URL is valid/invalid
*/
public isUrlValid = async (url: string, configName?: string): Promise<boolean> => {
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 })
.then(() => {
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;
});
};
Expand All @@ -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;
}
Expand Down

0 comments on commit b4c5739

Please sign in to comment.