Skip to content

Commit 46943b3

Browse files
authored
fix(web): Provide an actionable error message on DE errors CLOUDP-313461 (#6907)
* sanitize index errors * specific * copy
1 parent 69c9f16 commit 46943b3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/compass-indexes/src/modules/regular-indexes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ export const INITIAL_STATE: State = {
182182
error: undefined,
183183
};
184184

185+
function processError(error: string): string {
186+
const internalCodePattern = /[A-Z_]+:/; // Matches all caps with underscores followed by a colon anywhere in the string
187+
const httpCodePattern = /\b(4\d{2}|5\d{2})\b/; // Matches HTTP codes 400-599 anywhere in the string
188+
189+
if (internalCodePattern.test(error) || httpCodePattern.test(error)) {
190+
return "We're sorry, an unexpected error has occurred. Please try again.";
191+
}
192+
193+
return error; // Return original error if it doesn't match the patterns
194+
}
195+
185196
export default function reducer(
186197
state = INITIAL_STATE,
187198
action: AnyAction
@@ -248,7 +259,9 @@ export default function reducer(
248259
// previous list of indexes is shown to the user.
249260
// If fetch fails for refresh or polling, set the status to READY again.
250261
error:
251-
state.status === FetchStatuses.FETCHING ? action.error : state.error,
262+
state.status === FetchStatuses.FETCHING
263+
? processError(action.error)
264+
: state.error,
252265
status:
253266
state.status === FetchStatuses.FETCHING
254267
? FetchStatuses.ERROR

0 commit comments

Comments
 (0)