-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ 错误状态码重构为全局错误码(http状态码)&业务错误码(业务方自定义,只提供接口定义)
- Loading branch information
Showing
22 changed files
with
817 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
bubble-core/src/main/java/cn/fxbin/bubble/core/constant/YesOrNo.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
bubble-core/src/main/java/cn/fxbin/bubble/core/dataobject/BizErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cn.fxbin.bubble.core.dataobject; | ||
|
||
/** | ||
* BizErrorCode | ||
* | ||
* <p> | ||
* 业务状态码定义,业务方可做相应实现 | ||
* </p> | ||
* | ||
* @author fxbin | ||
* @version v1.0 | ||
* @since 2023/8/29 00:15 | ||
*/ | ||
public non-sealed interface BizErrorCode extends ErrorCode { | ||
|
||
/** | ||
* 错误码解析 | ||
* | ||
* @param errorCode 错误码 | ||
* @return {@link BizErrorCode} | ||
*/ | ||
BizErrorCode resolve(int errorCode); | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
bubble-core/src/main/java/cn/fxbin/bubble/core/dataobject/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cn.fxbin.bubble.core.dataobject; | ||
|
||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 错误代码 | ||
* ErrorCode | ||
* | ||
* <p>x | ||
* 分为两类: | ||
* 全局错误码(参照 {@link org.springframework.http.HttpStatus} 实现),实现为: {@code GlobalErrorCode} <br/> | ||
* 业务错误码 {@code BizErrorCode} <br/><br/> | ||
* <p> | ||
* 参照:<a href="https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status">HTTP 响应状态码</a> | ||
* </p> | ||
* | ||
* @author fxbin | ||
* @version v1.0 | ||
* @since 2023/08/29 00:44 | ||
*/ | ||
|
||
public sealed interface ErrorCode extends Serializable permits GlobalErrorCode, BizErrorCode { | ||
|
||
/** | ||
* Return the integer value of this status code. | ||
*/ | ||
int value(); | ||
|
||
/** | ||
* Return the String value of error reason phrase. | ||
*/ | ||
String reasonPhrase(); | ||
|
||
/** | ||
* Whether this status code is in the Informational class ({@code 1xx}). | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.1">RFC 2616</a> | ||
*/ | ||
default boolean is1xxInformational() { | ||
return false; | ||
}; | ||
|
||
/** | ||
* Whether this status code is in the Successful class ({@code 2xx}). | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.2">RFC 2616</a> | ||
*/ | ||
default boolean is2xxSuccessful() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Whether this status code is in the Redirection class ({@code 3xx}). | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.3">RFC 2616</a> | ||
*/ | ||
default boolean is3xxRedirection() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Whether this status code is in the Client Error class ({@code 4xx}). | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.4">RFC 2616</a> | ||
*/ | ||
default boolean is4xxClientError() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Whether this status code is in the Server Error class ({@code 5xx}). | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.5">RFC 2616</a> | ||
*/ | ||
default boolean is5xxServerError() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Whether this status code is in the Client or Server Error class | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.4">RFC 2616</a> | ||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-10.3">RFC 2616</a> | ||
* ({@code 4xx} or {@code 5xx}). | ||
* @see #is4xxClientError() | ||
* @see #is5xxServerError() | ||
*/ | ||
boolean isError(); | ||
|
||
default boolean isSameCodeAs(ErrorCode other) { | ||
return value() == other.value(); | ||
} | ||
|
||
static ErrorCode valueOf(int code) { | ||
GlobalErrorCode errorCode = GlobalErrorCode.resolve(code); | ||
if (errorCode != null) { | ||
return errorCode; | ||
} | ||
|
||
// TODO 实现对业务错误码的判断 | ||
|
||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.