From 715e03969ed7bd07f82253ac0b79bb5c3579bf34 Mon Sep 17 00:00:00 2001 From: Niva Vaani Sivakumar Date: Thu, 8 May 2025 12:02:49 -0400 Subject: [PATCH 1/3] sanitize index errors --- .../src/modules/regular-indexes.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/compass-indexes/src/modules/regular-indexes.ts b/packages/compass-indexes/src/modules/regular-indexes.ts index dbc86071170..c5ca82731b1 100644 --- a/packages/compass-indexes/src/modules/regular-indexes.ts +++ b/packages/compass-indexes/src/modules/regular-indexes.ts @@ -182,6 +182,18 @@ export const INITIAL_STATE: State = { error: undefined, }; +function processError(error: string): string { + const internalCodePattern = /[A-Z_]+:/; // Matches all caps with underscores followed by a colon anywhere in the string + const httpCodePattern = /\b(4\d{2}|5\d{2})\b/; // Matches HTTP codes 400-599 anywhere in the string + + if (internalCodePattern.test(error) || httpCodePattern.test(error)) { + console.log(error); + return 'Sorry, an unexpected error has occurred. Try refreshing the page or reporting the issue.'; + } + + return error; // Return original error if it doesn't match the patterns +} + export default function reducer( state = INITIAL_STATE, action: AnyAction @@ -248,7 +260,9 @@ export default function reducer( // previous list of indexes is shown to the user. // If fetch fails for refresh or polling, set the status to READY again. error: - state.status === FetchStatuses.FETCHING ? action.error : state.error, + state.status === FetchStatuses.FETCHING + ? processError(action.error) + : state.error, status: state.status === FetchStatuses.FETCHING ? FetchStatuses.ERROR From 9104ab8192537c3b8b91e6a4b79b108fccf4de9a Mon Sep 17 00:00:00 2001 From: Niva Vaani Sivakumar Date: Thu, 8 May 2025 12:05:47 -0400 Subject: [PATCH 2/3] specific --- packages/compass-indexes/src/modules/regular-indexes.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/compass-indexes/src/modules/regular-indexes.ts b/packages/compass-indexes/src/modules/regular-indexes.ts index c5ca82731b1..3362f5e3735 100644 --- a/packages/compass-indexes/src/modules/regular-indexes.ts +++ b/packages/compass-indexes/src/modules/regular-indexes.ts @@ -187,8 +187,7 @@ function processError(error: string): string { const httpCodePattern = /\b(4\d{2}|5\d{2})\b/; // Matches HTTP codes 400-599 anywhere in the string if (internalCodePattern.test(error) || httpCodePattern.test(error)) { - console.log(error); - return 'Sorry, an unexpected error has occurred. Try refreshing the page or reporting the issue.'; + return 'Sorry, an unexpected error has occurred. Try refreshing the page or reporting the issue if it persists.'; } return error; // Return original error if it doesn't match the patterns From 506d538a2505689f3cbd183ffd23caffbca06022 Mon Sep 17 00:00:00 2001 From: Niva Vaani Sivakumar Date: Thu, 8 May 2025 14:17:17 -0400 Subject: [PATCH 3/3] copy --- packages/compass-indexes/src/modules/regular-indexes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-indexes/src/modules/regular-indexes.ts b/packages/compass-indexes/src/modules/regular-indexes.ts index 3362f5e3735..62d4cd5db53 100644 --- a/packages/compass-indexes/src/modules/regular-indexes.ts +++ b/packages/compass-indexes/src/modules/regular-indexes.ts @@ -187,7 +187,7 @@ function processError(error: string): string { const httpCodePattern = /\b(4\d{2}|5\d{2})\b/; // Matches HTTP codes 400-599 anywhere in the string if (internalCodePattern.test(error) || httpCodePattern.test(error)) { - return 'Sorry, an unexpected error has occurred. Try refreshing the page or reporting the issue if it persists.'; + return "We're sorry, an unexpected error has occurred. Please try again."; } return error; // Return original error if it doesn't match the patterns