Compare commits
2 Commits
1.5.9branc
...
v1.5.12
| Author | SHA1 | Date | |
|---|---|---|---|
| e496f8fb7e | |||
| fda016d011 |
@@ -1,7 +1,7 @@
|
||||
## Version 1.5.9
|
||||
## Version 1.5.12
|
||||
|
||||
### Bugfix
|
||||
- Refactored clients to fix the problems with retries
|
||||
- Fix unhandled error in do() method for client and legacy-client
|
||||
|
||||
|
||||
|
||||
|
||||
40
client.go
40
client.go
@@ -145,19 +145,35 @@ 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)
|
||||
|
||||
// if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := dc.client.Do(req)
|
||||
if err != nil || resp == nil {
|
||||
if strings.Contains(err.Error(),"connection reset by peer") {
|
||||
resp.Body.Close()
|
||||
// }
|
||||
// }
|
||||
for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||
time.Sleep(5 *time.Second)
|
||||
resp, err = dc.client.Do(req)
|
||||
if strings.Contains(err.Error(),"connection reset by peer") {
|
||||
resp.Body.Close()
|
||||
continue
|
||||
} else if err == nil {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -142,19 +142,35 @@ 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)
|
||||
|
||||
// if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := ldc.client.Do(req)
|
||||
if err != nil || resp == nil {
|
||||
if strings.Contains(err.Error(),"connection reset by peer") {
|
||||
resp.Body.Close()
|
||||
// }
|
||||
// }
|
||||
for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||
time.Sleep(5 *time.Second)
|
||||
resp, err = ldc.client.Do(req)
|
||||
if strings.Contains(err.Error(),"connection reset by peer") {
|
||||
resp.Body.Close()
|
||||
continue
|
||||
} else if err == nil {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user