All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.jellyfin.sdk.api.client.RawResponse.kt Maven / Gradle / Ivy

There is a newer version: 1.5.5
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy