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

com.github.zhujk.resp.core.Resp.kt Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.github.zhujk.resp.core

import com.github.zhujk.resp.exception.RespException

const val SUCCESS: String = "success"
const val INTERNAL_ERROR: String = "The network is abnormal, please try again later"

data class Resp(
    val status: Int = 200,
    val msg: String = SUCCESS,
    val data: T? = null
) {
    constructor(data: T?) : this(200, SUCCESS, data)

    fun orElseThrow(): T? = when (status) {
        200 -> data
        else -> throw RespException(status, msg)
    }

    fun orElseThrow(f: (resp: Resp) -> Throwable): T? = when (status) {
        200 -> data
        else -> throw f(this)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy