From d2a2ffc1190fd05733751f8e8804ce99736aff58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=90=83=E7=82=B9=E8=8B=B9=E6=9E=9C?= <73388495+eatmoreapple@users.noreply.github.com> Date: Fri, 21 Oct 2022 18:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=B7=E6=B1=82=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E6=9C=BA=E5=88=B6=20(#117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 46d2d94..e03d672 100644 --- a/client.go +++ b/client.go @@ -71,11 +71,22 @@ func (c *Client) AddHttpHook(hooks ...HttpHook) { c.HttpHooks = append(c.HttpHooks, hooks...) } +const maxRetry = 2 + func (c *Client) do(req *http.Request) (*http.Response, error) { for _, hook := range c.HttpHooks { hook.BeforeRequest(req) } - resp, err := c.Client.Do(req) + var ( + resp *http.Response + err error + ) + for i := 0; i < maxRetry; i++ { + resp, err = c.Client.Do(req) + if err == nil { + break + } + } if err != nil { err = ErrorWrapper(NetworkErr, err.Error()) }