diff --git a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift index e52ad5bd32..6e40c7594b 100644 --- a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift +++ b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift @@ -543,51 +543,57 @@ public extension SearchClient { ) async throws -> ReplaceAllObjectsResponse { let tmpIndexName = "\(indexName)_tmp_\(Int.random(in: 1_000_000 ..< 10_000_000))" - var copyOperationResponse = try await operationIndex( - indexName: indexName, - operationIndexParams: OperationIndexParams( - operation: .copy, - destination: tmpIndexName, - scope: [.settings, .rules, .synonyms] - ), - requestOptions: requestOptions - ) + do { + var copyOperationResponse = try await operationIndex( + indexName: indexName, + operationIndexParams: OperationIndexParams( + operation: .copy, + destination: tmpIndexName, + scope: [.settings, .rules, .synonyms] + ), + requestOptions: requestOptions + ) - let batchResponses = try await self.chunkedBatch( - indexName: tmpIndexName, - objects: objects, - waitForTasks: true, - batchSize: batchSize, - requestOptions: requestOptions - ) - try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID) + let batchResponses = try await self.chunkedBatch( + indexName: tmpIndexName, + objects: objects, + waitForTasks: true, + batchSize: batchSize, + requestOptions: requestOptions + ) + try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID) - copyOperationResponse = try await operationIndex( - indexName: indexName, - operationIndexParams: OperationIndexParams( - operation: .copy, - destination: tmpIndexName, - scope: [.settings, .rules, .synonyms] - ), - requestOptions: requestOptions - ) - try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID) - - let moveOperationResponse = try await self.operationIndex( - indexName: tmpIndexName, - operationIndexParams: OperationIndexParams( - operation: .move, - destination: indexName - ), - requestOptions: requestOptions - ) - try await self.waitForTask(indexName: tmpIndexName, taskID: moveOperationResponse.taskID) + copyOperationResponse = try await operationIndex( + indexName: indexName, + operationIndexParams: OperationIndexParams( + operation: .copy, + destination: tmpIndexName, + scope: [.settings, .rules, .synonyms] + ), + requestOptions: requestOptions + ) + try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID) - return ReplaceAllObjectsResponse( - copyOperationResponse: copyOperationResponse, - batchResponses: batchResponses, - moveOperationResponse: moveOperationResponse - ) + let moveOperationResponse = try await self.operationIndex( + indexName: tmpIndexName, + operationIndexParams: OperationIndexParams( + operation: .move, + destination: indexName + ), + requestOptions: requestOptions + ) + try await self.waitForTask(indexName: tmpIndexName, taskID: moveOperationResponse.taskID) + + return ReplaceAllObjectsResponse( + copyOperationResponse: copyOperationResponse, + batchResponses: batchResponses, + moveOperationResponse: moveOperationResponse + ) + } catch { + _ = try? await deleteIndex(indexName: tmpIndexName) + + throw error + } } /// Generate a secured API key diff --git a/scripts/cts/testServer/replaceAllObjectsFailed.ts b/scripts/cts/testServer/replaceAllObjectsFailed.ts index 0c4f95cf85..589ecc3da7 100644 --- a/scripts/cts/testServer/replaceAllObjectsFailed.ts +++ b/scripts/cts/testServer/replaceAllObjectsFailed.ts @@ -4,7 +4,7 @@ import { expect } from 'chai'; import type { Express } from 'express'; import express from 'express'; -import { setupServer } from '.'; +import { setupServer } from './index.js'; const raoState: Record< string,