diff --git a/Sources/Search/Extra/SearchClientExtension.swift b/Sources/Search/Extra/SearchClientExtension.swift index e8100f96..5862dc8f 100644 --- a/Sources/Search/Extra/SearchClientExtension.swift +++ b/Sources/Search/Extra/SearchClientExtension.swift @@ -541,7 +541,7 @@ public extension SearchClient { batchSize: Int = 1000, requestOptions: RequestOptions? = nil ) async throws -> ReplaceAllObjectsResponse { - let tmpIndexName = try "\(indexName)_tmp_\(Int.random(in: 1_000_000 ..< 10_000_000))" + let tmpIndexName = "\(indexName)_tmp_\(Int.random(in: 1_000_000 ..< 10_000_000))" var copyOperationResponse = try await operationIndex( indexName: indexName, @@ -627,4 +627,14 @@ public extension SearchClient { return timestampDate.timeIntervalSince1970 - Date().timeIntervalSince1970 } + + func indexExists(indexName: String) async throws -> Bool { + do { + _ = try await self.getSettings(indexName: indexName) + } catch let AlgoliaError.httpError(error) where error.statusCode == 404 { + return false + } + + return true + } }