commonMain.org.jellyfin.sdk.api.client.RawResponse.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jellyfin-api-jvm Show documentation
Show all versions of jellyfin-api-jvm Show documentation
Official Kotlin/Java SDK for Jellyfin. org.jellyfin.sdk:jellyfin-api-jvm
package org.jellyfin.sdk.api.client
import io.ktor.utils.io.ByteReadChannel
import kotlinx.serialization.SerializationException
import mu.KotlinLogging
import org.jellyfin.sdk.api.client.exception.InvalidContentException
import org.jellyfin.sdk.api.client.util.ApiSerializer
public class RawResponse(
public val body: ByteReadChannel,
public val status: Int,
public val headers: Map>,
) {
public suspend inline fun createContent(): T {
val logger = KotlinLogging.logger {}
return try {
ApiSerializer.decodeResponseBody(body)
} catch (err: SerializationException) {
logger.error(err) { "Deserialization failed" }
throw InvalidContentException("Deserialization failed", err)
}
}
public suspend inline fun createResponse(): Response =
Response(createContent(), status, headers)
}