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