初始化
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.tongran.agent.client.exception;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.tongran.agent.client.exception.base.BaseException;
|
||||
import com.tongran.agent.client.exception.code.ErrorCode;
|
||||
|
||||
public class ServerException extends BaseException {
|
||||
|
||||
private static final long serialVersionUID = -519977195881081739L;
|
||||
|
||||
public ServerException(ErrorCode code) {
|
||||
super(code.getCode(), code.getMsg());
|
||||
}
|
||||
|
||||
public ServerException(Integer code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
|
||||
public ServerException(String msg) {
|
||||
super(500, msg);
|
||||
}
|
||||
|
||||
public ServerException(String msg, Object... arguments) {
|
||||
super(500, StrUtil.format(msg, arguments));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.tongran.agent.client.exception.base;
|
||||
|
||||
|
||||
import com.tongran.agent.client.exception.code.ErrorCode;
|
||||
|
||||
public class BaseException extends RuntimeException implements ErrorCode {
|
||||
|
||||
private static final long serialVersionUID = 1966249840643379123L;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
public BaseException() {
|
||||
}
|
||||
|
||||
public BaseException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public BaseException(Integer code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public BaseException(Integer code, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.tongran.agent.client.exception.code;
|
||||
|
||||
|
||||
import com.tongran.agent.client.utils.R;
|
||||
|
||||
public interface ErrorCode {
|
||||
|
||||
Integer getCode();
|
||||
|
||||
String getMsg();
|
||||
|
||||
default R<?> toResult() {
|
||||
return R.error(getMsg(), getCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.tongran.agent.client.exception.code;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum GlobalErrorCode implements ErrorCode {
|
||||
|
||||
SUCCESS(200, "成功"),
|
||||
|
||||
NOT_FOUND(404, "未找到相关资源"),
|
||||
|
||||
ERROR(500, "系统错误");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
private final String msg;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user