Commit 6723d6d8 authored by yanzg's avatar yanzg

升级新版本

parent bcb26273
......@@ -64,19 +64,22 @@ public class ExceptionHelper {
* @return 返回的数据
*/
public static ResponseResult<?> getError(Exception e, boolean isFull) {
if (e instanceof CodeTargetException) {
CodeTargetException code = (CodeTargetException) e;
return getError(code.getCode(), code.getMessage(), code.getTarget(), true);
} else if (e instanceof RuntimeCodeException) {
boolean isFullTo = e instanceof CodeTargetException || isFull;
boolean codeError = e instanceof CodeException;
ResponseResult<?> result;
if (e instanceof RuntimeCodeException) {
RuntimeCodeException code = (RuntimeCodeException) e;
return getError(code.getCode(), code.getMessage(), code.getTarget(), isFull);
result = getError(code.getCode(), code.getMessage(), code.getTarget(), isFullTo);
} else {
String msg = e.getMessage();
if (StringHelper.isEmpty(msg)) {
msg = e.getClass().getName();
}
return getError(ResultConstants.UNKNOW_ERROR, msg, e, isFull);
result = getError(ResultConstants.UNKNOW_ERROR, msg, e, isFullTo);
}
result.setCodeError(codeError);
return result;
}
private static ResponseResult<?> getError(String code, String msg, Object target, boolean isFull) {
......
......@@ -2,6 +2,7 @@ package com.yanzuoguang.util.vo;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.RuntimeCodeException;
import com.yanzuoguang.util.helper.StringHelper;
import io.swagger.annotations.ApiModelProperty;
......@@ -37,6 +38,54 @@ public class ResponseResult<T> extends BaseVo {
*/
@ApiModelProperty(value = "异常数据", notes = "当抛出异常时的数据,通常和code进行组合", required = true)
private Object target;
/**
* 是否是code错误
*/
@ApiModelProperty(value = "异常数据", notes = "当抛出异常时的数据,通常和code进行组合", required = true)
private boolean codeError = false;
/**
* 构造函数
*/
public ResponseResult() {
this(ResultConstants.SUCCESS, "操作成功");
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果消息
*/
public ResponseResult(String code, String message) {
this(code, message, null);
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public ResponseResult(String code, String message, T data) {
this(code, message, data, null);
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public ResponseResult(String code, String message, T data, Object target) {
this.code = code;
this.message = message;
this.data = data;
this.target = target;
}
/**
* 检查数据是否合法,不合法则抛出异常,合法则返回数据
......@@ -45,7 +94,12 @@ public class ResponseResult<T> extends BaseVo {
if (StringHelper.compare(code, ResultConstants.SUCCESS)) {
return this.data;
}
throw new CodeException(this.code, this.message, this.target);
if (this.codeError) {
throw new CodeException(this.code, this.message, this.target);
} else {
throw new RuntimeCodeException(this.code, this.message, this.target);
}
}
/**
......@@ -121,46 +175,21 @@ public class ResponseResult<T> extends BaseVo {
}
/**
* 构造函数
*/
public ResponseResult() {
this(ResultConstants.SUCCESS, "操作成功");
}
/**
* 构造函数
* 是否是code错误
*
* @param code 结果状态
* @param message 结果消息
* @return 是否是code错误
*/
public ResponseResult(String code, String message) {
this(code, message, null);
public boolean isCodeError() {
return codeError;
}
/**
* 构造函数
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
*/
public ResponseResult(String code, String message, T data) {
this(code, message, data, null);
}
/**
* 构造函数
* 设置code错误
*
* @param code 结果状态
* @param message 结果熊希
* @param data 结果
* @param codeError code错误
*/
public ResponseResult(String code, String message, T data, Object target) {
this.code = code;
this.message = message;
this.data = data;
this.target = target;
public void setCodeError(boolean codeError) {
this.codeError = codeError;
}
/**
......
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.vo.LogVo;
......@@ -67,11 +66,8 @@ public class AspectFeign {
// 假如是标准格式,则验证接口是否成功,不成功则抛出异常
if (result instanceof ResponseResult) {
ResponseResult<?> responseResult = (ResponseResult<?>) result;
if (!ResultConstants.SUCCESS.equals(responseResult.getCode())) {
throw new CodeException(responseResult.getCode(), responseResult.getMessage(), responseResult.getTarget());
}
responseResult.check();
}
return result;
} catch (CodeException e) {
ex = e;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment