@@ -642,57 +642,63 @@ export function createSearchClient({
642642 const randomSuffix = Math . floor ( Math . random ( ) * 1000000 ) + 100000 ;
643643 const tmpIndexName = `${ indexName } _tmp_${ randomSuffix } ` ;
644644
645- let copyOperationResponse = await this . operationIndex (
646- {
647- indexName,
648- operationIndexParams : {
649- operation : 'copy' ,
650- destination : tmpIndexName ,
651- scope : [ 'settings' , 'rules' , 'synonyms' ] ,
645+ try {
646+ let copyOperationResponse = await this . operationIndex (
647+ {
648+ indexName,
649+ operationIndexParams : {
650+ operation : 'copy' ,
651+ destination : tmpIndexName ,
652+ scope : [ 'settings' , 'rules' , 'synonyms' ] ,
653+ } ,
652654 } ,
653- } ,
654- requestOptions ,
655- ) ;
655+ requestOptions ,
656+ ) ;
656657
657- const batchResponses = await this . chunkedBatch (
658- { indexName : tmpIndexName , objects, waitForTasks : true , batchSize } ,
659- requestOptions ,
660- ) ;
658+ const batchResponses = await this . chunkedBatch (
659+ { indexName : tmpIndexName , objects, waitForTasks : true , batchSize } ,
660+ requestOptions ,
661+ ) ;
661662
662- await this . waitForTask ( {
663- indexName : tmpIndexName ,
664- taskID : copyOperationResponse . taskID ,
665- } ) ;
663+ await this . waitForTask ( {
664+ indexName : tmpIndexName ,
665+ taskID : copyOperationResponse . taskID ,
666+ } ) ;
666667
667- copyOperationResponse = await this . operationIndex (
668- {
669- indexName,
670- operationIndexParams : {
671- operation : 'copy' ,
672- destination : tmpIndexName ,
673- scope : [ 'settings' , 'rules' , 'synonyms' ] ,
668+ copyOperationResponse = await this . operationIndex (
669+ {
670+ indexName,
671+ operationIndexParams : {
672+ operation : 'copy' ,
673+ destination : tmpIndexName ,
674+ scope : [ 'settings' , 'rules' , 'synonyms' ] ,
675+ } ,
674676 } ,
675- } ,
676- requestOptions ,
677- ) ;
678- await this . waitForTask ( {
679- indexName : tmpIndexName ,
680- taskID : copyOperationResponse . taskID ,
681- } ) ;
677+ requestOptions ,
678+ ) ;
679+ await this . waitForTask ( {
680+ indexName : tmpIndexName ,
681+ taskID : copyOperationResponse . taskID ,
682+ } ) ;
682683
683- const moveOperationResponse = await this . operationIndex (
684- {
684+ const moveOperationResponse = await this . operationIndex (
685+ {
686+ indexName : tmpIndexName ,
687+ operationIndexParams : { operation : 'move' , destination : indexName } ,
688+ } ,
689+ requestOptions ,
690+ ) ;
691+ await this . waitForTask ( {
685692 indexName : tmpIndexName ,
686- operationIndexParams : { operation : 'move' , destination : indexName } ,
687- } ,
688- requestOptions ,
689- ) ;
690- await this . waitForTask ( {
691- indexName : tmpIndexName ,
692- taskID : moveOperationResponse . taskID ,
693- } ) ;
693+ taskID : moveOperationResponse . taskID ,
694+ } ) ;
694695
695- return { copyOperationResponse, batchResponses, moveOperationResponse } ;
696+ return { copyOperationResponse, batchResponses, moveOperationResponse } ;
697+ } catch ( error ) {
698+ await this . deleteIndex ( { indexName : tmpIndexName } ) ;
699+
700+ throw error ;
701+ }
696702 } ,
697703
698704 async indexExists ( { indexName } : GetSettingsProps ) : Promise < boolean > {
0 commit comments