com.github.zhujk.resp.core.Resp.kt Maven / Gradle / Ivy
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