@@ -472,46 +472,52 @@ public suspend fun SearchClient.replaceAllObjects(
472472): ReplaceAllObjectsResponse {
473473 val tmpIndexName = " ${indexName} _tmp_${Random .nextInt(from = 0 , until = 100 )} "
474474
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+ )
484485
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+ )
493494
494- waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
495+ waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
495496
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)
506507
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)
513518
514- return ReplaceAllObjectsResponse (copy, batchResponses, move)
519+ throw e
520+ }
515521}
516522
517523/* *
@@ -542,6 +548,13 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
542548 return validUntil - Clock .System .now()
543549}
544550
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+ */
545558public suspend fun SearchClient.indexExists (indexName : String ): Boolean {
546559 try {
547560 getSettings(indexName)
0 commit comments