29 lines
539 B
Go
29 lines
539 B
Go
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 {
|
|
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)
|
|
}
|
|
|
|
func (err Error) Err() error {
|
|
if err.Code == 0 {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|