mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
release: v1.9.0
This commit is contained in:
@@ -42,7 +42,7 @@ func IsTrue(exp bool, msg string, params ...any) {
|
||||
}
|
||||
}
|
||||
|
||||
func IsTrueBy(exp bool, err errorx.BizError) {
|
||||
func IsTrueBy(exp bool, err *errorx.BizError) {
|
||||
if !exp {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ type BizError struct {
|
||||
}
|
||||
|
||||
var (
|
||||
Success BizError = NewBizCode(200, "success")
|
||||
BizErr BizError = NewBizCode(400, "biz error")
|
||||
ServerError BizError = NewBizCode(500, "server error")
|
||||
PermissionErr BizError = NewBizCode(501, "token error")
|
||||
AccessTokenInvalid BizError = NewBizCode(502, "access token invalid")
|
||||
Success *BizError = NewBizCode(200, "success")
|
||||
BizErr *BizError = NewBizCode(400, "biz error")
|
||||
ServerError *BizError = NewBizCode(500, "server error")
|
||||
PermissionErr *BizError = NewBizCode(501, "token error")
|
||||
AccessTokenInvalid *BizError = NewBizCode(502, "access token invalid")
|
||||
)
|
||||
|
||||
// 错误消息
|
||||
@@ -33,11 +33,11 @@ func (e BizError) String() string {
|
||||
}
|
||||
|
||||
// 创建业务逻辑错误结构体,默认为业务逻辑错误
|
||||
func NewBiz(msg string, formats ...any) BizError {
|
||||
return BizError{code: BizErr.code, err: fmt.Sprintf(msg, formats...)}
|
||||
func NewBiz(msg string, formats ...any) *BizError {
|
||||
return &BizError{code: BizErr.code, err: fmt.Sprintf(msg, formats...)}
|
||||
}
|
||||
|
||||
// 创建业务逻辑错误结构体,可设置指定错误code
|
||||
func NewBizCode(code int16, msg string, formats ...any) BizError {
|
||||
return BizError{code: code, err: fmt.Sprintf(msg, formats...)}
|
||||
func NewBizCode(code int16, msg string, formats ...any) *BizError {
|
||||
return &BizError{code: code, err: fmt.Sprintf(msg, formats...)}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func SuccessNoData() *Result {
|
||||
return &Result{Code: SuccessCode, Msg: SuccessMsg}
|
||||
}
|
||||
|
||||
func Error(bizerr errorx.BizError) *Result {
|
||||
func Error(bizerr *errorx.BizError) *Result {
|
||||
return &Result{Code: bizerr.Code(), Msg: bizerr.Error()}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ func getErrMsg(rc *Ctx, err any) string {
|
||||
nFrames := DefaultLogFrames
|
||||
var errMsg string
|
||||
switch t := err.(type) {
|
||||
case errorx.BizError:
|
||||
case *errorx.BizError:
|
||||
errMsg = fmt.Sprintf("\n<-e %s", t.String())
|
||||
nFrames = nFrames / 2
|
||||
case error:
|
||||
|
||||
@@ -102,7 +102,7 @@ func (rc *Ctx) GetLogInfo() *LogInfo {
|
||||
func (rc *Ctx) res() {
|
||||
if err := rc.Error; err != nil {
|
||||
switch t := err.(type) {
|
||||
case errorx.BizError:
|
||||
case *errorx.BizError:
|
||||
rc.JSONRes(http.StatusOK, model.Error(t))
|
||||
default:
|
||||
logx.ErrorTrace("服务器错误", t)
|
||||
|
||||
Reference in New Issue
Block a user