From fda016d011425bd0f7249f9238a3530b32b397b8 Mon Sep 17 00:00:00 2001 From: Sergey Kisil Date: Wed, 29 Nov 2023 11:57:03 +0300 Subject: [PATCH] v1.5.11 --- CHANGELOG.md | 4 ++-- client.go | 25 +++++++++++++------------ legacy-client.go | 25 +++++++++++++------------ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6468edb..ca08282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ -## Version 1.5.9 +## Version 1.5.11 ### Bugfix -- Refactored clients to fix the problems with retries +- Fix unhandled error in do() method for client and legacy-client diff --git a/client.go b/client.go index f79bf0a..7c2f9c4 100644 --- a/client.go +++ b/client.go @@ -145,19 +145,20 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) { buf, _ := io.ReadAll(req.Body) // for i := uint64(0); i < dc.cfg.Retries; i++ { - // req = req.Clone(req.Context()) - req.Body = io.NopCloser(bytes.NewBuffer(buf)) - resp, err := dc.client.Do(req) + // req = req.Clone(req.Context()) + req.Body = io.NopCloser(bytes.NewBuffer(buf)) + resp, err := dc.client.Do(req) + if err != nil || resp == nil { + return resp, err + } - // if err == nil { - if resp.StatusCode == 200 { - return resp, err - } - respBytes, _ := io.ReadAll(resp.Body) - err = fmt.Errorf("%s", respBytes) - resp.Body.Close() - // } - // } + if resp.StatusCode == 200 { + return resp, nil + } + respBytes, _ := io.ReadAll(resp.Body) + err = fmt.Errorf("%s", respBytes) + resp.Body.Close() + return nil, fmt.Errorf("could not execute request: %w", err) } diff --git a/legacy-client.go b/legacy-client.go index 477f282..d2917c7 100644 --- a/legacy-client.go +++ b/legacy-client.go @@ -142,19 +142,20 @@ func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) { buf, _ := io.ReadAll(req.Body) // for i := uint64(0); i < ldc.cfg.Retries; i++ { - // req = req.Clone(req.Context()) - req.Body = io.NopCloser(bytes.NewBuffer(buf)) - resp, err := ldc.client.Do(req) + // req = req.Clone(req.Context()) + req.Body = io.NopCloser(bytes.NewBuffer(buf)) + resp, err := ldc.client.Do(req) + if err != nil || resp == nil { + return resp, err + } - // if err == nil { - if resp.StatusCode == 200 { - return resp, err - } - respBytes, _ := io.ReadAll(resp.Body) - err = fmt.Errorf("%s", respBytes) - resp.Body.Close() - // } - // } + if resp.StatusCode == 200 { + return resp, nil + } + respBytes, _ := io.ReadAll(resp.Body) + err = fmt.Errorf("%s", respBytes) + resp.Body.Close() + return nil, fmt.Errorf("could not execute request: %w", err) }