This commit is contained in:
withchao
2023-03-14 19:33:44 +08:00
parent 9bb30406ee
commit 6a95025e41
10 changed files with 334 additions and 90 deletions
+12
View File
@@ -9,6 +9,7 @@ import (
type CodeError interface {
Code() int
Msg() string
Is(err error) bool
Wrap(msg ...string) error
error
}
@@ -38,6 +39,17 @@ func (e *codeError) Wrap(w ...string) error {
return errors.Wrap(e, strings.Join(w, ", "))
}
func (e *codeError) Is(err error) bool {
if err == nil {
return false
}
codeErr, ok := Unwrap(err).(CodeError)
if ok {
return codeErr.Code() == e.code
}
return false
}
func (e *codeError) Error() string {
return fmt.Sprintf("[%d]%s", e.code, e.msg)
}