Skip to content

Commit 509f56d

Browse files
algolia-botmillotpFluf22
committed
feat(clients): add helper to check if an index exists (generated)
algolia/api-clients-automation#3646 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent 560f9b0 commit 509f56d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/scala/algoliasearch/extension/package.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,5 +395,16 @@ package object extension {
395395
moveOperationResponse = move
396396
)
397397
}
398+
399+
def indexExists(indexName: String)(implicit ec: ExecutionContext): Future[Boolean] = {
400+
try {
401+
client.getSettings(indexName)
402+
} catch {
403+
case apiError: AlgoliaApiException if apiError.httpErrorCode == 404 => Future.successful(false)
404+
case e: Throwable => throw e
405+
}
406+
407+
Future.successful(true)
408+
}
398409
}
399410
}

0 commit comments

Comments
 (0)