@@ -472,46 +472,52 @@ public suspend fun SearchClient.replaceAllObjects(
472
472
): ReplaceAllObjectsResponse {
473
473
val tmpIndexName = " ${indexName} _tmp_${Random .nextInt(from = 0 , until = 100 )} "
474
474
475
- var copy = operationIndex(
476
- indexName = indexName,
477
- operationIndexParams = OperationIndexParams (
478
- operation = OperationType .Copy ,
479
- destination = tmpIndexName,
480
- scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
481
- ),
482
- requestOptions = requestOptions,
483
- )
475
+ try {
476
+ var copy = operationIndex(
477
+ indexName = indexName,
478
+ operationIndexParams = OperationIndexParams (
479
+ operation = OperationType .Copy ,
480
+ destination = tmpIndexName,
481
+ scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
482
+ ),
483
+ requestOptions = requestOptions,
484
+ )
484
485
485
- val batchResponses = this .chunkedBatch(
486
- indexName = tmpIndexName,
487
- objects = objects,
488
- action = Action .AddObject ,
489
- waitForTask = true ,
490
- batchSize = batchSize,
491
- requestOptions = requestOptions,
492
- )
486
+ val batchResponses = this .chunkedBatch(
487
+ indexName = tmpIndexName,
488
+ objects = objects,
489
+ action = Action .AddObject ,
490
+ waitForTask = true ,
491
+ batchSize = batchSize,
492
+ requestOptions = requestOptions,
493
+ )
493
494
494
- waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
495
+ waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
495
496
496
- copy = operationIndex(
497
- indexName = indexName,
498
- operationIndexParams = OperationIndexParams (
499
- operation = OperationType .Copy ,
500
- destination = tmpIndexName,
501
- scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
502
- ),
503
- requestOptions = requestOptions,
504
- )
505
- waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
497
+ copy = operationIndex(
498
+ indexName = indexName,
499
+ operationIndexParams = OperationIndexParams (
500
+ operation = OperationType .Copy ,
501
+ destination = tmpIndexName,
502
+ scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
503
+ ),
504
+ requestOptions = requestOptions,
505
+ )
506
+ waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
506
507
507
- val move = operationIndex(
508
- indexName = tmpIndexName,
509
- operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
510
- requestOptions = requestOptions,
511
- )
512
- waitForTask(indexName = tmpIndexName, taskID = move.taskID)
508
+ val move = operationIndex(
509
+ indexName = tmpIndexName,
510
+ operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
511
+ requestOptions = requestOptions,
512
+ )
513
+ waitForTask(indexName = tmpIndexName, taskID = move.taskID)
514
+
515
+ return ReplaceAllObjectsResponse (copy, batchResponses, move)
516
+ } catch (e: Exception ) {
517
+ deleteIndex(tmpIndexName)
513
518
514
- return ReplaceAllObjectsResponse (copy, batchResponses, move)
519
+ throw e
520
+ }
515
521
}
516
522
517
523
/* *
@@ -542,6 +548,13 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
542
548
return validUntil - Clock .System .now()
543
549
}
544
550
551
+ /* *
552
+ * Checks that an index exists.
553
+ *
554
+ * @param indexName The name of the index to check.
555
+ * @return true if the index exists, false otherwise.
556
+ * @throws AlgoliaApiException if an error occurs during the request.
557
+ */
545
558
public suspend fun SearchClient.indexExists (indexName : String ): Boolean {
546
559
try {
547
560
getSettings(indexName)
0 commit comments