异常信息实体类
@Data
public class GlobalException extends RuntimeException {
private static final long serialVersionUID = 5983014993412756767L;
private String code;
private String msg;
private Exception exception;
public GlobalException(final String code, final String msg, final Exception e) {
super(String.valueOf(code).concat(msg));
this.code = code;
this.msg = msg;
this.exception = e;
}
public GlobalException(final String code, final String msg) {
super(String.valueOf(code).concat(msg));
this.code = code;
this.msg = msg;
}
public GlobalException(ResultEnum resultEnum, final Exception e) {
super(String.valueOf(resultEnum.getCode()).concat(resultEnum.getMsg()));
this.code = resultEnum.getCode();
this.msg = resultEnum.getMsg();
this.exception = e;
}
public GlobalException(ResultEnum resultEnum) {
super(String.valueOf(resultEnum.getCode()).concat(resultEnum.getMsg()));
this.code = resultEnum.getCode();
this.msg = resultEnum.getMsg();
this.exception = null;
}
}
使用
throw new GlobalException(ResultEnum.ERROR_2016);
return ResultUtil.Error(new GlobalException(ResultEnum.ERROR_2013));