错误码统一进行配置,不作为异常的字段。异常通过 getType 标识不同错误类型。

This commit is contained in:
2024-08-27 19:00:38 +08:00
parent a59cadc537
commit 6d76e9d524
6 changed files with 118 additions and 39 deletions

View File

@@ -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 <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/
public abstract class BaseException
extends Exception
implements IWithCode<String> {
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;
}
}