feiyu02
2025-03-28 7d74f3fd087d4a8192ed556a6c2e3a2ea3c81cff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 = "服务器出现内部错误")
    }
}