File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
packages/compass-indexes/src/modules Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,18 @@ 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+ console . log ( error ) ;
191+ return 'Sorry, an unexpected error has occurred. Try refreshing the page or reporting the issue.' ;
192+ }
193+
194+ return error ; // Return original error if it doesn't match the patterns
195+ }
196+
185197export default function reducer (
186198 state = INITIAL_STATE ,
187199 action : AnyAction
@@ -248,7 +260,9 @@ export default function reducer(
248260 // previous list of indexes is shown to the user.
249261 // If fetch fails for refresh or polling, set the status to READY again.
250262 error :
251- state . status === FetchStatuses . FETCHING ? action . error : state . error ,
263+ state . status === FetchStatuses . FETCHING
264+ ? processError ( action . error )
265+ : state . error ,
252266 status :
253267 state . status === FetchStatuses . FETCHING
254268 ? FetchStatuses . ERROR
You can’t perform that action at this time.
0 commit comments