添加NetworkErr
This commit is contained in:
parent
76eeb065e4
commit
ba4857f2d3
@ -74,6 +74,9 @@ func (c *Client) do(req *http.Request) (*http.Response, error) {
|
|||||||
hook.BeforeRequest(req)
|
hook.BeforeRequest(req)
|
||||||
}
|
}
|
||||||
resp, err := c.Client.Do(req)
|
resp, err := c.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
err = NetworkErr{error: err}
|
||||||
|
}
|
||||||
for _, hook := range c.HttpHooks {
|
for _, hook := range c.HttpHooks {
|
||||||
hook.AfterRequest(resp, err)
|
hook.AfterRequest(resp, err)
|
||||||
}
|
}
|
||||||
|
11
items.go
11
items.go
@ -240,3 +240,14 @@ type PushLoginResponse struct {
|
|||||||
func (p PushLoginResponse) Ok() bool {
|
func (p PushLoginResponse) Ok() bool {
|
||||||
return p.Ret == "0" && p.UUID != ""
|
return p.Ret == "0" && p.UUID != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NetworkErr struct{ error }
|
||||||
|
|
||||||
|
func (n NetworkErr) Unwrap() error {
|
||||||
|
return n.error
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNetworkError(err error) bool {
|
||||||
|
_, ok := err.(NetworkErr)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user