Skip to content

Commit a5da61e

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 2135cd4 commit a5da61e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

client/src/commonMain/kotlin/com/algolia/client/extensions/SearchClient.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,16 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
521521
val validUntil = Instant.fromEpochMilliseconds(match.groupValues[1].toLong())
522522
return validUntil - Clock.System.now()
523523
}
524+
525+
public suspend fun SearchClient.indexExists(indexName: String): Boolean {
526+
try {
527+
getSettings(indexName)
528+
} catch (e: AlgoliaApiException) {
529+
if (e.httpErrorCode == 404) {
530+
return false
531+
}
532+
throw e
533+
}
534+
535+
return true
536+
}

0 commit comments

Comments
 (0)