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.
49 lines
677 B
49 lines
677 B
package errs
|
|
|
|
import (
|
|
"OpenIM/pkg/utils"
|
|
"fmt"
|
|
"github.com/pkg/errors"
|
|
"strings"
|
|
)
|
|
|
|
type Coderr interface {
|
|
Code() int
|
|
Msg() string
|
|
Warp(msg ...string) error
|
|
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
|
|
}
|
|
|
|
func (e *errInfo) Warp(w ...string) error {
|
|
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 {
|
|
return utils.Unwrap(err)
|
|
}
|