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 +}