This commit is contained in:
withchao
2023-03-07 11:12:39 +08:00
parent 5ca36ebc10
commit 1513933922
8 changed files with 195 additions and 40 deletions
+2 -34
View File
@@ -7,16 +7,10 @@ import (
"strings"
)
type Code interface {
type Coderr interface {
Code() int
Msg() string
}
type Coderr interface {
Code
Detail() string
WithDetail(string) Coderr
Warp(...string) error
Warp(msg ...string) error
error
}
@@ -33,15 +27,6 @@ type errInfo struct {
detail string
}
func (e *errInfo) WithDetail(s string) Coderr {
if e.detail == "" {
e.detail = s
} else {
e.detail = s + ", " + e.detail
}
return e
}
func (e *errInfo) Code() int {
return e.code
}
@@ -50,10 +35,6 @@ func (e *errInfo) Msg() string {
return e.msg
}
func (e *errInfo) Detail() string {
return e.detail
}
func (e *errInfo) Warp(w ...string) error {
return errors.Wrap(e, strings.Join(w, ", "))
}
@@ -65,16 +46,3 @@ func (e *errInfo) Error() string {
func Unwrap(err error) error {
return utils.Unwrap(err)
}
func GetCode(err error) Code {
if err == nil {
return NewCodeError(UnknownCode, "nil")
}
if code, ok := Unwrap(err).(Code); ok {
if code.Code() == 0 {
return NewCodeError(UnknownCode, "code == 0")
}
return code
}
return NewCodeError(UnknownCode, "unknown code")
}