Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/compass-indexes/src/modules/regular-indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ 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)) {
return "We're sorry, an unexpected error has occurred. Please try again.";
}

return error; // Return original error if it doesn't match the patterns
}

export default function reducer(
state = INITIAL_STATE,
action: AnyAction
Expand Down Expand Up @@ -248,7 +259,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
Expand Down
Loading