首页 > 其他分享 >RespUtils

RespUtils

时间:2024-11-15 10:21:03浏览次数:1  
标签:errCode ret response static returnType RespUtils public

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());
}
)

标签:errCode,ret,response,static,returnType,RespUtils,public
From: https://www.cnblogs.com/lmzzr24/p/18547461

相关文章