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

commonMain.com.javiersc.resources.networkResponse.NetworkResponse.kt Maven / Gradle / Ivy

There is a newer version: 0.7.1
Show newest version
package com.javiersc.resources.networkResponse

import io.ktor.http.Headers
import io.ktor.http.HttpStatusCode
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable

/**
 * Sealed class which cover usual use cases related which network responses
 */
@Serializable
public sealed class NetworkResponse {

    @Serializable
    public data class Success(
        val data: NR,
        @Contextual
        val status: HttpStatusCode,
        val headers: Headers,
    ) : NetworkResponse()

    @Serializable
    public data class Error(
        val error: E?,
        @Contextual
        val status: HttpStatusCode,
        val headers: Headers,
    ) : NetworkResponse<@Contextual Nothing, E>()

    @Serializable
    public data class UnknownError(
        @Contextual val throwable: Throwable
    ) : NetworkResponse<@Contextual Nothing, @Contextual Nothing>()

    @Serializable
    public data class InternetNotAvailable(
        val error: String
    ) : NetworkResponse<@Contextual Nothing, @Contextual Nothing>()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy