feiyu02
2025-09-30 a3cc1d220f8a1de11874bebceba0130d32157ff1
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 ?: "", stackTrace = e.stackTraceToString())
    } catch (e: Exception) {
        // fixme: to log system
        e.printStackTrace()
        BaseResponse(false, message = "服务器出现内部错误", stackTrace =  e.stackTraceToString())
    }
}