|
|
@ -11,6 +11,7 @@ public class AppRet<T> { |
|
|
|
AppRetEcodeInfo ecode; |
|
|
|
T data; |
|
|
|
long timestamp;//接口请求时间 |
|
|
|
String traceInfo; |
|
|
|
|
|
|
|
public AppRet() { |
|
|
|
this.timestamp = System.currentTimeMillis(); |
|
|
@ -32,6 +33,10 @@ public class AppRet<T> { |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
public String getTraceInfo() { |
|
|
|
return traceInfo; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static <T> AppRet<T> success(T data) { |
|
|
|
AppRet<T> r = new AppRet<>(); |
|
|
@ -73,12 +78,27 @@ public class AppRet<T> { |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> AppRet<T> fail(HardwareException e) { |
|
|
|
AppRet<T> r = new AppRet<>(); |
|
|
|
r.suc = false; |
|
|
|
r.ecode = new AppRetEcodeInfo(e.getErrorCode(), e.getModuleId(), e.getCmdId()); |
|
|
|
r.data = null; |
|
|
|
public static <T> AppRet<T> fail(Exception e) { |
|
|
|
StringBuilder traceSb = new StringBuilder(); |
|
|
|
for (var trace : e.getStackTrace()) { |
|
|
|
traceSb.append(trace.toString()).append("\n"); |
|
|
|
} |
|
|
|
String trace = traceSb.toString(); |
|
|
|
AppRet<T> r = new AppRet<>(); |
|
|
|
|
|
|
|
if (e instanceof HardwareException hexcep) { |
|
|
|
r.suc = false; |
|
|
|
r.ecode = new AppRetEcodeInfo(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); |
|
|
|
r.data = null; |
|
|
|
r.traceInfo = trace; |
|
|
|
} else { |
|
|
|
r.suc = false; |
|
|
|
r.ecode = new AppRetEcodeInfo(A8kEcode.CodeException, null, null); |
|
|
|
r.data = null; |
|
|
|
r.traceInfo = trace; |
|
|
|
} |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |