package cn.flightfeather.supervision.lightshare.web
|
|
import cn.flightfeather.supervision.common.exception.BizException
|
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
|
import cn.flightfeather.supervision.lightshare.vo.DataHead
|
|
/**
|
* 包装接口返回结果
|
*/
|
fun resPack(service: () -> Any?): BaseResponse<Any> {
|
return try {
|
val res = service()
|
if (res is Pair<*, *>) {
|
val head = res.first
|
if (head is DataHead) {
|
BaseResponse(true, head = head, data = res.second)
|
} else {
|
BaseResponse(true, data = res)
|
}
|
} else {
|
BaseResponse(true, data = res)
|
}
|
} catch (e: BizException) {
|
BaseResponse(false, message = e.message ?: "")
|
} catch (e: Exception) {
|
// fixme: to log system
|
|
BaseResponse(false, message = "服务器出现内部错误")
|
}
|
}
|