refactor: align framework cleanup with new bootstrap flow
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -15,10 +15,9 @@ var (
|
||||
|
||||
// AppError 表示带错误码的应用错误
|
||||
type AppError struct {
|
||||
Code int // 应用错误码
|
||||
Message string // 错误消息
|
||||
HTTPStatus int // HTTP 状态码(自动从 Code 映射,可通过 WithHTTPStatus 覆盖)
|
||||
Err error // 底层错误(可选)
|
||||
Code int // 应用错误码
|
||||
Message string // 错误消息
|
||||
Err error // 底层错误(可选)
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string {
|
||||
@@ -39,9 +38,8 @@ func New(code int, message string) *AppError {
|
||||
message = GetMessage(code, "zh-CN")
|
||||
}
|
||||
return &AppError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
HTTPStatus: GetHTTPStatus(code), // 自动从错误码映射 HTTP 状态码
|
||||
Code: code,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +50,8 @@ func Wrap(code int, message string, err error) *AppError {
|
||||
message = GetMessage(code, "zh-CN")
|
||||
}
|
||||
return &AppError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
HTTPStatus: GetHTTPStatus(code), // 自动从错误码映射 HTTP 状态码
|
||||
Err: err,
|
||||
Code: code,
|
||||
Message: message,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
// WithHTTPStatus 设置自定义 HTTP 状态码(用于特殊场景)
|
||||
func (e *AppError) WithHTTPStatus(status int) *AppError {
|
||||
e.HTTPStatus = status
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user