package com.ys.bdtp.adm.mvvm.model


/**
 * 网络请求
 *
 * @param block 请求方法
 * @return [Response] 请求结果封装
 */
suspend fun <T> request(block: suspend () -> Model<T>): Response<T> {
    return try {
        val model = block()
        if (model.result == "success") {
            Response.create(model.data)
        } else {
            Response.create(model.message ?: "request ok, but no data")
        }
    } catch (e: Throwable) {
        Response.create(e.message ?: "request crash but nothing")
    }
}