Skip to content

Commit

Permalink
feat(clients): add helper to check if an index exists (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3646

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 4, 2024
1 parent 560f9b0 commit 509f56d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/scala/algoliasearch/extension/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,16 @@ package object extension {
moveOperationResponse = move
)
}

def indexExists(indexName: String)(implicit ec: ExecutionContext): Future[Boolean] = {
try {
client.getSettings(indexName)
} catch {
case apiError: AlgoliaApiException if apiError.httpErrorCode == 404 => Future.successful(false)
case e: Throwable => throw e
}

Future.successful(true)
}
}
}

0 comments on commit 509f56d

Please sign in to comment.