添加NetworkErr

This commit is contained in:
eatmoreapple 2021-08-24 15:58:26 +08:00
parent 76eeb065e4
commit ba4857f2d3
2 changed files with 14 additions and 0 deletions

View File

@ -74,6 +74,9 @@ func (c *Client) do(req *http.Request) (*http.Response, error) {
hook.BeforeRequest(req)
}
resp, err := c.Client.Do(req)
if err != nil {
err = NetworkErr{error: err}
}
for _, hook := range c.HttpHooks {
hook.AfterRequest(resp, err)
}

View File

@ -240,3 +240,14 @@ type PushLoginResponse struct {
func (p PushLoginResponse) Ok() bool {
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
}