@@ -412,6 +412,19 @@ export const fetchIndexSuggestions = ({
412
412
}
413
413
}
414
414
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
+
415
428
// Analyze namespace and fetch suggestions
416
429
try {
417
430
const analyzedNamespace = mql . analyzeNamespace (
@@ -426,6 +439,14 @@ export const fetchIndexSuggestions = ({
426
439
const results = await mql . suggestIndex ( [ query ] ) ;
427
440
const indexSuggestions = results ?. index ;
428
441
442
+ if (
443
+ ! indexSuggestions ||
444
+ Object . keys ( indexSuggestions as Record < string , unknown > ) . length === 0
445
+ ) {
446
+ throwError ( ) ;
447
+ return ;
448
+ }
449
+
429
450
dispatch ( {
430
451
type : ActionTypes . SuggestedIndexesFetched ,
431
452
sampleDocs : sampleDocuments ,
@@ -434,18 +455,8 @@ export const fetchIndexSuggestions = ({
434
455
indexSuggestionsState : 'success' ,
435
456
} ) ;
436
457
} 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
-
448
458
track ( 'Error parsing query' , { context : 'Create Index Modal' } ) ;
459
+ throwError ( e ) ;
449
460
}
450
461
} ;
451
462
} ;
@@ -509,7 +520,7 @@ export const createIndexFormSubmitted = (): IndexesThunkAction<
509
520
510
521
const formIndexOptions = getState ( ) . createIndex . options ;
511
522
512
- let spec : Record < string , IndexDirection > ;
523
+ let spec : Record < string , IndexDirection > = { } ;
513
524
514
525
try {
515
526
if ( isQueryFlow ) {
0 commit comments