File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
packages/compass-indexes/src/modules Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff 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+
185196export 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
You can’t perform that action at this time.
0 commit comments