RespUtils

public class RespUtils{
private static final Logger log=LoggerFactory. getLogger(RespUtils. class);
private RespUtils(){
}
public static void setSuccess(BaseResponse response){
response. setSuccess();

public static void setError( Exception e, ErrCodeBaseEnum errCode, BaseResponse response){
if (e instanceof BaseBizException){
BaseBizException exception=(BaseBizException)e;
response. setErrCode( exception. getErrCode());
response. setErrMsg( exception. getErrMsg());
} else if (errCode!= null){
response. setErrCode(errCode. getErrCode());
response. setErrMsg(errCode. getErrMsg());
} else{
log. error("errCode为空, 设置默认错误");
response. setErrCode(HadesErrCodeEnum. BIZ_UNKNOWN_ERROR. getErrCode());
response. setErrMsg(HadesErrCodeEnum. BIZ_UNKNOWN_ERROR. getErrMsg());
}
)
public static void setError(ErrCodeBaseEnum errCode, BaseResponse response){setError(( Exception) null, errCode, response);
}
public static Object newReturn( Class returnType, String errCode, String errMsg){ if (returnType == null){ return null; } else{ Object ret= null; try{ret=returnType. newInstance(); if ( ret instanceof BaseResponse){ BaseResponse response=(BaseResponse) ret; response. setErrCode(errCode); response. setErrMsg(errMsg); ret= response; } } catch (IllegalAccessException| InstantiationException var5){ log.info ((String)null,var5); } return ret; } ) public static Object newReturn( Class returnType, BaseBizExceptione){
return newReturn(returnType, e. getErrCode(), e. getErrMsg());
}
public static Object newReturn( Class<?> returnType, ErrCodeBaseEnum
errCodeBaseEnum){
return newReturn(returnType, errCodeBaseEnum. getErrCode(),
errCodeBaseEnum. getErrMsg());
}
)

posted @ 2024-11-15 10:20  一曲微茫  阅读(3)  评论(0编辑  收藏  举报