@@ -412,6 +412,19 @@ export const fetchIndexSuggestions = ({
412412 }
413413 }
414414
415+ const throwError = ( e ?: unknown ) => {
416+ dispatch ( {
417+ type : ActionTypes . SuggestedIndexesFetched ,
418+ sampleDocs : sampleDocuments || [ ] ,
419+ indexSuggestions : null ,
420+ error :
421+ e instanceof Error
422+ ? 'Error parsing query. Please follow query structure. ' + e . message
423+ : 'Error parsing query. Please follow query structure.' ,
424+ indexSuggestionsState : 'error' ,
425+ } ) ;
426+ } ;
427+
415428 // Analyze namespace and fetch suggestions
416429 try {
417430 const analyzedNamespace = mql . analyzeNamespace (
@@ -426,6 +439,14 @@ export const fetchIndexSuggestions = ({
426439 const results = await mql . suggestIndex ( [ query ] ) ;
427440 const indexSuggestions = results ?. index ;
428441
442+ if (
443+ ! indexSuggestions ||
444+ Object . keys ( indexSuggestions as Record < string , unknown > ) . length === 0
445+ ) {
446+ throwError ( ) ;
447+ return ;
448+ }
449+
429450 dispatch ( {
430451 type : ActionTypes . SuggestedIndexesFetched ,
431452 sampleDocs : sampleDocuments ,
@@ -434,18 +455,8 @@ export const fetchIndexSuggestions = ({
434455 indexSuggestionsState : 'success' ,
435456 } ) ;
436457 } catch ( e : unknown ) {
437- dispatch ( {
438- type : ActionTypes . SuggestedIndexesFetched ,
439- sampleDocs : sampleDocuments ,
440- indexSuggestions : null ,
441- error :
442- e instanceof Error
443- ? 'Error parsing query. Please follow query structure. ' + e . message
444- : 'Error parsing query. Please follow query structure.' ,
445- indexSuggestionsState : 'error' ,
446- } ) ;
447-
448458 track ( 'Error parsing query' , { context : 'Create Index Modal' } ) ;
459+ throwError ( e ) ;
449460 }
450461 } ;
451462} ;
@@ -509,7 +520,7 @@ export const createIndexFormSubmitted = (): IndexesThunkAction<
509520
510521 const formIndexOptions = getState ( ) . createIndex . options ;
511522
512- let spec : Record < string , IndexDirection > ;
523+ let spec : Record < string , IndexDirection > = { } ;
513524
514525 try {
515526 if ( isQueryFlow ) {
0 commit comments