mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
improvements in HttpResponse.bodyOrNull
This commit is contained in:
parent
ef9b31aee0
commit
95be1a26f2
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.16.9
|
## 0.16.9
|
||||||
|
|
||||||
|
* `Ktor`:
|
||||||
|
* `Client`
|
||||||
|
* `HttpResponse.bodyOrNull` now retrieve callback to check if body should be received or null
|
||||||
|
|
||||||
## 0.16.8
|
## 0.16.8
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -4,6 +4,6 @@ import io.ktor.client.call.body
|
|||||||
import io.ktor.client.statement.HttpResponse
|
import io.ktor.client.statement.HttpResponse
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
|
|
||||||
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull() = takeIf {
|
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull(
|
||||||
status == HttpStatusCode.OK
|
statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK }
|
||||||
} ?.body<T>()
|
) = takeIf(statusFilter) ?.body<T>()
|
||||||
|
Loading…
Reference in New Issue
Block a user