Skip to content

Commit

Permalink
[1.x][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.

Include using default messages.

Backport PR:
opensearch-project#941

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Jan 10, 2022
1 parent 39fa939 commit aefe924
Show file tree
Hide file tree
Showing 2 changed files with 18 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
19 changes: 13 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,21 @@ 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. Using default branding.`);
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. Using default branding.`);
return false;
});
};
Expand All @@ -338,12 +343,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. Using default title.`
);
return false;
}
Expand Down

0 comments on commit aefe924

Please sign in to comment.