@@ -559,51 +559,57 @@ public extension SearchClient {
559
559
) async throws -> ReplaceAllObjectsResponse {
560
560
let tmpIndexName = " \( indexName) _tmp_ \( Int . random ( in: 1_000_000 ..< 10_000_000 ) ) "
561
561
562
- var copyOperationResponse = try await operationIndex (
563
- indexName: indexName,
564
- operationIndexParams: OperationIndexParams (
565
- operation: . copy,
566
- destination: tmpIndexName,
567
- scope: [ . settings, . rules, . synonyms]
568
- ) ,
569
- requestOptions: requestOptions
570
- )
562
+ do {
563
+ var copyOperationResponse = try await operationIndex (
564
+ indexName: indexName,
565
+ operationIndexParams: OperationIndexParams (
566
+ operation: . copy,
567
+ destination: tmpIndexName,
568
+ scope: [ . settings, . rules, . synonyms]
569
+ ) ,
570
+ requestOptions: requestOptions
571
+ )
571
572
572
- let batchResponses = try await self . chunkedBatch (
573
- indexName: tmpIndexName,
574
- objects: objects,
575
- waitForTasks: true ,
576
- batchSize: batchSize,
577
- requestOptions: requestOptions
578
- )
579
- try await self . waitForTask ( indexName: tmpIndexName, taskID: copyOperationResponse. taskID)
573
+ let batchResponses = try await self . chunkedBatch (
574
+ indexName: tmpIndexName,
575
+ objects: objects,
576
+ waitForTasks: true ,
577
+ batchSize: batchSize,
578
+ requestOptions: requestOptions
579
+ )
580
+ try await self . waitForTask ( indexName: tmpIndexName, taskID: copyOperationResponse. taskID)
580
581
581
- copyOperationResponse = try await operationIndex (
582
- indexName: indexName,
583
- operationIndexParams: OperationIndexParams (
584
- operation: . copy,
585
- destination: tmpIndexName,
586
- scope: [ . settings, . rules, . synonyms]
587
- ) ,
588
- requestOptions: requestOptions
589
- )
590
- try await self . waitForTask ( indexName: tmpIndexName, taskID: copyOperationResponse. taskID)
591
-
592
- let moveOperationResponse = try await self . operationIndex (
593
- indexName: tmpIndexName,
594
- operationIndexParams: OperationIndexParams (
595
- operation: . move,
596
- destination: indexName
597
- ) ,
598
- requestOptions: requestOptions
599
- )
600
- try await self . waitForTask ( indexName: tmpIndexName, taskID: moveOperationResponse. taskID)
582
+ copyOperationResponse = try await operationIndex (
583
+ indexName: indexName,
584
+ operationIndexParams: OperationIndexParams (
585
+ operation: . copy,
586
+ destination: tmpIndexName,
587
+ scope: [ . settings, . rules, . synonyms]
588
+ ) ,
589
+ requestOptions: requestOptions
590
+ )
591
+ try await self . waitForTask ( indexName: tmpIndexName, taskID: copyOperationResponse. taskID)
601
592
602
- return ReplaceAllObjectsResponse (
603
- copyOperationResponse: copyOperationResponse,
604
- batchResponses: batchResponses,
605
- moveOperationResponse: moveOperationResponse
606
- )
593
+ let moveOperationResponse = try await self . operationIndex (
594
+ indexName: tmpIndexName,
595
+ operationIndexParams: OperationIndexParams (
596
+ operation: . move,
597
+ destination: indexName
598
+ ) ,
599
+ requestOptions: requestOptions
600
+ )
601
+ try await self . waitForTask ( indexName: tmpIndexName, taskID: moveOperationResponse. taskID)
602
+
603
+ return ReplaceAllObjectsResponse (
604
+ copyOperationResponse: copyOperationResponse,
605
+ batchResponses: batchResponses,
606
+ moveOperationResponse: moveOperationResponse
607
+ )
608
+ } catch {
609
+ _ = try ? await self . deleteIndex ( indexName: tmpIndexName)
610
+
611
+ throw error
612
+ }
607
613
}
608
614
609
615
/// Generate a secured API key
0 commit comments