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) }