diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java index f09195f..a8b91ad 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java @@ -16,8 +16,6 @@ package xyz.zhouxy.plusone.commons.exception; -import xyz.zhouxy.plusone.commons.base.IWithCode; - import javax.annotation.Nonnull; import java.util.Objects; @@ -27,32 +25,30 @@ import java.util.Objects; * @author ZhouXY */ public abstract class BaseException - extends Exception - implements IWithCode { + extends Exception { private static final long serialVersionUID = -2546365325001947203L; @Nonnull - private final String code; + private final String type; - protected BaseException(String code, String msg) { + protected BaseException(String type, String msg) { super(msg); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } - protected BaseException(String code, Throwable cause) { + protected BaseException(String type, Throwable cause) { super(cause); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } - protected BaseException(String code, String msg, Throwable cause) { + protected BaseException(String type, String msg, Throwable cause) { super(msg, cause); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } @Nonnull - @Override - public final String getCode() { - return this.code; + public final String getType() { + return this.type; } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseRuntimeException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseRuntimeException.java index 61fae62..6dbdf68 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseRuntimeException.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseRuntimeException.java @@ -16,8 +16,6 @@ package xyz.zhouxy.plusone.commons.exception; -import xyz.zhouxy.plusone.commons.base.IWithCode; - import javax.annotation.Nonnull; import java.util.Objects; @@ -26,33 +24,30 @@ import java.util.Objects; * * @author ZhouXY */ -public abstract class BaseRuntimeException - extends RuntimeException - implements IWithCode { +public abstract class BaseRuntimeException extends RuntimeException { private static final long serialVersionUID = -6345888403567792664L; @Nonnull - private final String code; + private final String type; - protected BaseRuntimeException(String code, String msg) { + protected BaseRuntimeException(String type, String msg) { super(msg); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } - protected BaseRuntimeException(String code, Throwable cause) { + protected BaseRuntimeException(String type, Throwable cause) { super(cause); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } - protected BaseRuntimeException(String code, String msg, Throwable cause) { + protected BaseRuntimeException(String type, String msg, Throwable cause) { super(msg, cause); - this.code = Objects.requireNonNull(code); + this.type = Objects.requireNonNull(type); } @Nonnull - @Override - public final String getCode() { - return this.code; + public final String getType() { + return this.type; } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/BizException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BizException.java new file mode 100644 index 0000000..e21c3ce --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BizException.java @@ -0,0 +1,36 @@ +package xyz.zhouxy.plusone.commons.exception; + +/** + * 业务异常 + * + * @author ZhouXY + */ +public class BizException extends BaseRuntimeException { + private static final long serialVersionUID = -5524759033245815405L; + + protected BizException(String type, String msg) { + super(type, msg); + } + + protected BizException(String type, Throwable cause) { + super(type, cause); + } + + protected BizException(String type, String msg, Throwable cause) { + super(type, msg, cause); + } + + private static final String DEFAULT = "0"; + + public static BizException of(String msg) { + return new BizException(DEFAULT, msg); + } + + public static BizException of(Throwable cause) { + return new BizException(DEFAULT, cause); + } + + public static BizException of(String msg, Throwable cause) { + return new BizException(DEFAULT, msg, cause); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/SysException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/SysException.java new file mode 100644 index 0000000..b859696 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/SysException.java @@ -0,0 +1,31 @@ +package xyz.zhouxy.plusone.commons.exception; + +public class SysException extends BaseRuntimeException { + private static final long serialVersionUID = 8821240827443168118L; + + protected SysException(String type, String msg) { + super(type, msg); + } + + protected SysException(String type, Throwable cause) { + super(type, cause); + } + + protected SysException(String type, String msg, Throwable cause) { + super(type, msg, cause); + } + + private static final String DEFAULT = "0"; + + public static SysException of(String msg) { + return new SysException(DEFAULT, msg); + } + + public static SysException of(Throwable cause) { + return new SysException(DEFAULT, cause); + } + + public static SysException of(String msg, Throwable cause) { + return new SysException(DEFAULT, msg, cause); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/ThirdPartySystemException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/ThirdPartySystemException.java new file mode 100644 index 0000000..a88227a --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/ThirdPartySystemException.java @@ -0,0 +1,31 @@ +package xyz.zhouxy.plusone.commons.exception; + +public class ThirdPartySystemException extends BaseRuntimeException { + private static final long serialVersionUID = 20240827113826L; + + protected ThirdPartySystemException(String type, String msg) { + super(type, msg); + } + + protected ThirdPartySystemException(String type, Throwable cause) { + super(type, cause); + } + + protected ThirdPartySystemException(String type, String msg, Throwable cause) { + super(type, msg, cause); + } + + private static final String DEFAULT = "0"; + + public static ThirdPartySystemException of(String msg) { + return new ThirdPartySystemException(DEFAULT, msg); + } + + public static ThirdPartySystemException of(Throwable cause) { + return new ThirdPartySystemException(DEFAULT, cause); + } + + public static ThirdPartySystemException of(String msg, Throwable cause) { + return new ThirdPartySystemException(DEFAULT, msg, cause); + } +} diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/dto/UnifiedResponse.java b/src/main/java/xyz/zhouxy/plusone/commons/model/dto/UnifiedResponse.java index 01965e7..76395d4 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/model/dto/UnifiedResponse.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/model/dto/UnifiedResponse.java @@ -24,8 +24,6 @@ import javax.annotation.Nullable; import com.google.common.base.Preconditions; -import xyz.zhouxy.plusone.commons.base.IWithCode; - /** * 统一结果,对返回给前端的数据进行封装。 * @@ -70,10 +68,6 @@ public abstract class UnifiedResponse { return new ErrorResult(status, e); } - public static > UnifiedResponse error(E e) { - return new ErrorResult(e); - } - public static UnifiedResponse of(Object status, @Nullable String message) { return new CustomResult(status, message); } @@ -195,10 +189,6 @@ public abstract class UnifiedResponse { ErrorResult(Object status, Throwable e) { super(status, Objects.requireNonNull(e).getMessage()); } - - > ErrorResult(E e) { - super(e.getCode(), e.getMessage()); - } } /**