You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/errs/coderr.go

57 lines
768 B

2 years ago
package errs
import (
"fmt"
"github.com/pkg/errors"
"strings"
)
2 years ago
type Coderr interface {
2 years ago
Code() int
Msg() string
2 years ago
Wrap(msg ...string) error
2 years ago
error
}
func NewCodeError(code int, msg string) Coderr {
return &errInfo{
code: code,
msg: msg,
}
}
type errInfo struct {
code int
msg string
detail string
}
func (e *errInfo) Code() int {
return e.code
}
func (e *errInfo) Msg() string {
return e.msg
}
2 years ago
func (e *errInfo) Wrap(w ...string) error {
2 years ago
return errors.Wrap(e, strings.Join(w, ", "))
}
func (e *errInfo) Error() string {
return fmt.Sprintf("[%d]%s", e.code, e.msg)
}
func Unwrap(err error) error {
2 years ago
for err != nil {
unwrap, ok := err.(interface {
Unwrap() error
})
if !ok {
break
}
err = unwrap.Unwrap()
}
return err
2 years ago
}