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