From 566dcad53a35077a16634014680f2311c0ba7e15 Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Tue, 29 Aug 2023 11:32:37 +0300 Subject: [PATCH 1/3] wrap validator in try catch to prevent failure --- .../auto-complete/auto-complete.util.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts index 9e348e7f2..0a8a0b88e 100644 --- a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts +++ b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts @@ -58,12 +58,16 @@ function getErrorMessage(queryUrl: string) { } function getValidationError(queryUrl: string): string | null { - const validator = new ValidatedUrl(); - const validation = validator.validate(queryUrl); - if (!validation.success) { - return queryUrl.substring(validation.matched, validation.maxMatched); + try { + const validator = new ValidatedUrl(); + const validation = validator.validate(queryUrl); + if (!validation.success) { + return queryUrl.substring(validation.matched, validation.maxMatched); + } + throw new Error('Validation unsuccessful'); + } catch (error) { + return null; } - return null; } function getSearchText(input: string, index: number) { From 7e387727f7fa063676c06eddee7805bf193a5eaf Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Thu, 7 Sep 2023 10:42:52 +0300 Subject: [PATCH 2/3] return null instead of throwing an error --- .../query-input/auto-complete/auto-complete.util.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts index 0a8a0b88e..6f75d2873 100644 --- a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts +++ b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts @@ -51,7 +51,7 @@ function getErrorMessage(queryUrl: string) { if (error) { return `${translateMessage('Possible error found in URL near')}: ${error}`; } - if (queryUrl.indexOf('graph.microsoft.com') === -1){ + if (queryUrl.indexOf('graph.microsoft.com') === -1) { return translateMessage('The URL must contain graph.microsoft.com'); } return ''; @@ -63,8 +63,9 @@ function getValidationError(queryUrl: string): string | null { const validation = validator.validate(queryUrl); if (!validation.success) { return queryUrl.substring(validation.matched, validation.maxMatched); + } else { + return null; } - throw new Error('Validation unsuccessful'); } catch (error) { return null; } From 173cd0e26655b3ddf2d320bc29bcdfb82fe2c6e9 Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Thu, 7 Sep 2023 10:43:57 +0300 Subject: [PATCH 3/3] use shorthand --- .../query-input/auto-complete/auto-complete.util.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts index 6f75d2873..53dda6658 100644 --- a/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts +++ b/src/app/views/query-runner/query-input/auto-complete/auto-complete.util.ts @@ -61,11 +61,8 @@ function getValidationError(queryUrl: string): string | null { try { const validator = new ValidatedUrl(); const validation = validator.validate(queryUrl); - if (!validation.success) { - return queryUrl.substring(validation.matched, validation.maxMatched); - } else { - return null; - } + return (!validation.success) ? + queryUrl.substring(validation.matched, validation.maxMatched) : null; } catch (error) { return null; }