From a9f7fd8e328e2e7d815a8e22180d1e9db3cc99a8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 10 Feb 2023 15:17:08 +0600 Subject: [PATCH] new extension HttpResponse.bodyOrNullOnNoContent --- CHANGELOG.md | 1 + .../kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f104a5c4759..d4141580fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * `Ktor`: * `Client` * `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null + * New extension `HttpResponse.bodyOrNullOnNoContent` ## 0.16.8 diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt index 251d5ab3703..c3f2bedc83d 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/BodyOrNull.kt @@ -7,3 +7,7 @@ import io.ktor.http.HttpStatusCode suspend inline fun HttpResponse.bodyOrNull( statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK } ) = takeIf(statusFilter) ?.body() + +suspend inline fun HttpResponse.bodyOrNullOnNoContent() = bodyOrNull { + it.status != HttpStatusCode.NoContent +}