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

commonMain.SpineFailure.kt Maven / Gradle / Ivy

The newest version!
package opensavvy.spine

sealed class SpineFailure {

    abstract val type: Type

    abstract val payload: Payload?

    data class Message(
        override val type: Type,
        val message: String? = null,
    ) : SpineFailure() {
        override val payload: Nothing?
            get() = null

        override fun toString() = "$type: “${message}”"
    }

    data class Payload(
        override val type: Type,
        override val payload: Payload,
    ) : SpineFailure() {

        override fun toString() = "$type: “${payload}”"
    }

    enum class Type {
        Unauthenticated,
        Unauthorized,
        NotFound,
        InvalidRequest,
        InvalidState,
        ;
    }
}

fun SpineFailure(
    type: SpineFailure.Type,
    message: String? = null,
) = SpineFailure.Message(type, message)

fun  SpineFailure(
    type: SpineFailure.Type,
    payload: Payload,
) = SpineFailure.Payload(type, payload)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy