Skip to content

Commit defff12

Browse files
committed
feat: 针对各模块添加异常类
1 parent 5ef1668 commit defff12

21 files changed

Lines changed: 200 additions & 147 deletions

File tree

common/core/src/main/java/top/cadecode/uniboot/common/core/exception/UniErrorCode.java renamed to common/core/src/main/java/top/cadecode/uniboot/common/core/enums/ApiErrorCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package top.cadecode.uniboot.common.core.exception;
1+
package top.cadecode.uniboot.common.core.enums;
22

33
import top.cadecode.uniboot.common.core.web.response.ApiStatus;
44

@@ -8,7 +8,7 @@
88
* @author Cade Li
99
* @date 2022/5/8
1010
*/
11-
public interface UniErrorCode {
11+
public interface ApiErrorCode {
1212

1313
String DEFAULT_CODE = "UNKNOWN";
1414
String DEFAULT_MESSAGE = "未知错误";
@@ -28,5 +28,5 @@ default int getStatus() {
2828
/**
2929
* 未知异常
3030
*/
31-
UniErrorCode UNKNOWN = new UniErrorCode() {};
31+
ApiErrorCode UNKNOWN = new ApiErrorCode() {};
3232
}

common/core/src/main/java/top/cadecode/uniboot/common/core/enums/CommonErrorEnum.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

common/core/src/main/java/top/cadecode/uniboot/common/core/exception/UniException.java renamed to common/core/src/main/java/top/cadecode/uniboot/common/core/exception/ApiException.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package top.cadecode.uniboot.common.core.exception;
22

33
import lombok.Getter;
4+
import top.cadecode.uniboot.common.core.enums.ApiErrorCode;
45

56
import java.util.Objects;
67

@@ -11,12 +12,12 @@
1112
* @date 2022/5/8
1213
*/
1314
@Getter
14-
public class UniException extends RuntimeException {
15+
public class ApiException extends RuntimeException {
1516

1617
/**
1718
* 错误信息码
1819
*/
19-
private final UniErrorCode errorCode;
20+
private final ApiErrorCode errorCode;
2021

2122
/**
2223
* 更多错误信息
@@ -27,31 +28,31 @@ public class UniException extends RuntimeException {
2728
* 抛出未知异常
2829
*
2930
* @param moreInfo 更多异常信息
30-
* @return UniException
31+
* @return ApiException
3132
*/
32-
public static UniException of(String moreInfo) {
33-
return of(UniErrorCode.UNKNOWN, moreInfo);
33+
public static ApiException of(String moreInfo) {
34+
return of(ApiErrorCode.UNKNOWN, moreInfo);
3435
}
3536

3637
/**
3738
* 抛出未知异常
3839
*
3940
* @param throwable cause
4041
* @param moreInfo 更多异常信息
41-
* @return UniException
42+
* @return ApiException
4243
*/
43-
public static UniException of(Throwable throwable, String moreInfo) {
44-
return of(UniErrorCode.UNKNOWN, throwable, moreInfo);
44+
public static ApiException of(Throwable throwable, String moreInfo) {
45+
return of(ApiErrorCode.UNKNOWN, throwable, moreInfo);
4546
}
4647

4748
/**
4849
* 根据 ApiErrorCode 抛出异常
4950
*
5051
* @param errorCode 错误信息码
5152
* @param moreInfo 更多异常信息
52-
* @return UniException
53+
* @return ApiException
5354
*/
54-
public static UniException of(UniErrorCode errorCode, String moreInfo) {
55+
public static ApiException of(ApiErrorCode errorCode, String moreInfo) {
5556
return of(errorCode, null, moreInfo);
5657
}
5758

@@ -60,9 +61,9 @@ public static UniException of(UniErrorCode errorCode, String moreInfo) {
6061
*
6162
* @param errorCode 错误信息码
6263
* @param throwable cause
63-
* @return UniException
64+
* @return ApiException
6465
*/
65-
public static UniException of(UniErrorCode errorCode, Throwable throwable) {
66+
public static ApiException of(ApiErrorCode errorCode, Throwable throwable) {
6667
return of(errorCode, throwable, null);
6768
}
6869

@@ -72,10 +73,10 @@ public static UniException of(UniErrorCode errorCode, Throwable throwable) {
7273
* @param errorCode 错误信息码
7374
* @param throwable cause
7475
* @param moreInfo 更多异常信息
75-
* @return UniException
76+
* @return ApiException
7677
*/
77-
public static UniException of(UniErrorCode errorCode, Throwable throwable, String moreInfo) {
78-
return new UniException(errorCode, throwable, moreInfo);
78+
public static ApiException of(ApiErrorCode errorCode, Throwable throwable, String moreInfo) {
79+
return new ApiException(errorCode, throwable, moreInfo);
7980
}
8081

8182
/**
@@ -85,7 +86,7 @@ public static UniException of(UniErrorCode errorCode, Throwable throwable, Strin
8586
* @param throwable cause
8687
* @param moreInfo 更多异常信息
8788
*/
88-
private UniException(UniErrorCode errorCode, Throwable throwable, String moreInfo) {
89+
private ApiException(ApiErrorCode errorCode, Throwable throwable, String moreInfo) {
8990
super(generateMessage(errorCode, moreInfo), throwable);
9091
this.errorCode = errorCode;
9192
this.moreInfo = moreInfo;
@@ -98,7 +99,7 @@ private UniException(UniErrorCode errorCode, Throwable throwable, String moreInf
9899
* @param moreInfo 更多异常信息
99100
* @return 完整异常信息
100101
*/
101-
private static String generateMessage(UniErrorCode errorCode, String moreInfo) {
102+
private static String generateMessage(ApiErrorCode errorCode, String moreInfo) {
102103
String message = "";
103104
// 拼接 [错误码-错误信息]
104105
if (Objects.nonNull(errorCode)) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package top.cadecode.uniboot.common.core.exception;
2+
3+
/**
4+
* 工具类异常
5+
*
6+
* @author Cade Li
7+
* @date 2023/6/9
8+
*/
9+
public class UtilException extends RuntimeException {
10+
public UtilException() {
11+
}
12+
13+
public UtilException(String message) {
14+
super(message);
15+
}
16+
17+
public UtilException(String message, Throwable cause) {
18+
super(message, cause);
19+
}
20+
21+
public UtilException(Throwable cause) {
22+
super(cause);
23+
}
24+
25+
public UtilException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
26+
super(message, cause, enableSuppression, writableStackTrace);
27+
}
28+
}

0 commit comments

Comments
 (0)