|
|
|
@ -140,25 +140,22 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
|
|
|
|
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
|
|
|
|
req.Header.Set("Accept", "application/json")
|
|
|
|
|
|
|
|
|
|
// var resp *http.Response
|
|
|
|
|
// var err 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.Close = true
|
|
|
|
|
if err != nil || resp == nil {
|
|
|
|
|
if strings.Contains(err.Error(),"connection reset by peer") {
|
|
|
|
|
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)
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
resp, err = dc.client.Do(req)
|
|
|
|
|
if strings.Contains(err.Error(),"connection reset by peer") {
|
|
|
|
|
if strings.Contains(err.Error(), "connection reset by peer") {
|
|
|
|
|
resp.Body.Close()
|
|
|
|
|
continue
|
|
|
|
|
} else if err == nil {
|
|
|
|
|
break
|
|
|
|
|
break
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -174,6 +171,6 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
|
|
|
|
respBytes, _ := io.ReadAll(resp.Body)
|
|
|
|
|
err = fmt.Errorf("%s", respBytes)
|
|
|
|
|
resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
|
|
|
}
|
|
|
|
|