29 lines
539 B
Go
Raw Normal View History

2021-10-28 00:59:04 +08:00
package request
import "fmt"
type Error struct {
Code int32 `json:"errcode"`
Msg string `json:"errmsg"`
}
func (err Error) IsZero() bool {
// return reflect.DeepEqual(err, Error{}) || reflect.DeepEqual(err, Error{Code: 0, Msg: "ok"})
return err.Code == 0
}
func (err Error) Error() string {
2021-11-10 01:44:51 +08:00
text, ok := ErrCodeText[err.Code]
if ok {
return fmt.Sprintf("%d:%s, %s", err.Code, err.Msg, text)
}
return fmt.Sprintf("%d:%s", err.Code, err.Msg)
2021-10-28 00:59:04 +08:00
}
func (err Error) Err() error {
if err.Code == 0 {
return nil
}
return err
}