更新 response 错误处理
This commit is contained in:
parent
6d7541a8ed
commit
d51ad8cdff
2
bot.go
2
bot.go
@ -268,7 +268,7 @@ func (b *Bot) syncCheck() error {
|
|||||||
}
|
}
|
||||||
// 如果不是正常的状态码返回,发生了错误,直接退出
|
// 如果不是正常的状态码返回,发生了错误,直接退出
|
||||||
if !resp.Success() {
|
if !resp.Success() {
|
||||||
return resp
|
return resp.Err()
|
||||||
}
|
}
|
||||||
// 如果Selector不为0,则获取消息
|
// 如果Selector不为0,则获取消息
|
||||||
if !resp.NorMal() {
|
if !resp.NorMal() {
|
||||||
|
@ -94,7 +94,7 @@ func (c *Caller) GetLoginInfo(body []byte) (*LoginInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !loginInfo.Ok() {
|
if !loginInfo.Ok() {
|
||||||
return nil, loginInfo
|
return nil, loginInfo.Err()
|
||||||
}
|
}
|
||||||
return &loginInfo, nil
|
return &loginInfo, nil
|
||||||
}
|
}
|
||||||
|
18
items.go
18
items.go
@ -1,6 +1,7 @@
|
|||||||
package openwechat
|
package openwechat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,8 +24,11 @@ func (l LoginInfo) Ok() bool {
|
|||||||
return l.Ret == 0
|
return l.Ret == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l LoginInfo) Error() string {
|
func (l LoginInfo) Err() error {
|
||||||
return l.Message
|
if l.Ok() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New(l.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseRequest 初始的请求信息
|
// BaseRequest 初始的请求信息
|
||||||
@ -100,13 +104,15 @@ func (s SyncCheckResponse) NorMal() bool {
|
|||||||
return s.Success() && s.Selector == "0"
|
return s.Success() && s.Selector == "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实现error接口
|
func (s SyncCheckResponse) Err() error {
|
||||||
func (s SyncCheckResponse) Error() string {
|
if s.Success() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
i, err := strconv.ParseInt(s.RetCode, 16, 10)
|
i, err := strconv.ParseInt(s.RetCode, 16, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return errors.New("sync check unknown error")
|
||||||
}
|
}
|
||||||
return Ret(i).String()
|
return errors.New(Ret(i).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebWxSyncResponse struct {
|
type WebWxSyncResponse struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user