You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package nerr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Error struct {
|
|
|
|
Code uint32 `json:"code"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewError(code uint32, msg string) error {
|
|
|
|
return &Error{
|
|
|
|
Code: code,
|
|
|
|
Msg: msg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWithMsg(msg string) error {
|
|
|
|
return NewError(ServerCommonError, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWithMsgf(format string, args ...any) error {
|
|
|
|
return NewWithMsg(fmt.Sprintf(format, args))
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWithCode(code uint32) error {
|
|
|
|
return NewError(code, MapErrMsg(code))
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWithErr(err error) error {
|
|
|
|
cause := errors.Cause(err)
|
|
|
|
if e, ok := cause.(*Error); ok {
|
|
|
|
return e
|
|
|
|
} else {
|
|
|
|
return NewWithMsg(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Error) Error() string {
|
|
|
|
return fmt.Sprintf("errorCode:%d, errorMsg:%s", e.Code, e.Msg)
|
|
|
|
}
|