mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-08 17:49:44 +00:00
improvements in HttpResponse.bodyOrNull
This commit is contained in:
@@ -4,6 +4,6 @@ import io.ktor.client.call.body
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.HttpStatusCode
|
||||
|
||||
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull() = takeIf {
|
||||
status == HttpStatusCode.OK
|
||||
} ?.body<T>()
|
||||
suspend inline fun <reified T : Any> HttpResponse.bodyOrNull(
|
||||
statusFilter: (HttpResponse) -> Boolean = { it.status == HttpStatusCode.OK }
|
||||
) = takeIf(statusFilter) ?.body<T>()
|
||||
|
Reference in New Issue
Block a user