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.
32 lines
562 B
Go
32 lines
562 B
Go
3 years ago
|
package nerr
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
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 (e *Error) Error() string {
|
||
|
return fmt.Sprintf("errorCode:%d, errorMsg:%s", e.Code, e.Msg)
|
||
|
}
|