code error

This commit is contained in:
withchao
2023-03-16 16:32:42 +08:00
parent 38d3c5d94d
commit 1f935531f6
7 changed files with 272 additions and 15 deletions
+20
View File
@@ -9,6 +9,8 @@ import (
type CodeError interface {
Code() int
Msg() string
Detail() string
WithDetail(detail string) CodeError
Is(err error) bool
Wrap(msg ...string) error
error
@@ -35,6 +37,24 @@ func (e *codeError) Msg() string {
return e.msg
}
func (e *codeError) Detail() string {
return e.detail
}
func (e *codeError) WithDetail(detail string) CodeError {
var d string
if e.detail == "" {
d = detail
} else {
d = e.detail + ", " + detail
}
return &codeError{
code: e.code,
msg: e.msg,
detail: d,
}
}
func (e *codeError) Wrap(w ...string) error {
return errors.Wrap(e, strings.Join(w, ", "))
}