repair fixes

This commit is contained in:
Ben Sarmiento
2023-11-11 03:30:10 +01:00
parent cd96c7bd38
commit 531624ee82
4 changed files with 21 additions and 20 deletions

View File

@@ -1,7 +1,6 @@
package http
import (
"io"
"net/http"
"strings"
"time"
@@ -54,14 +53,10 @@ func NewHTTPClient(token string, maxRetries int, c config.ConfigInterface) *HTTP
if err != nil {
return true
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
body, _ := io.ReadAll(resp.Body)
body2, _ := io.ReadAll(resp.Request.Body)
log.Errorf("Received a %s %s from %s", resp.Status, string(body), resp.Request.URL)
log.Errorf("request %s %s", string(body2), resp.Request.URL)
if resp.StatusCode == 429 {
return true
}
// no need to retry because the status code is 2XX
// no need to retry
return false
},
log: logutil.NewLogger().Named("http"),

View File

@@ -153,7 +153,6 @@ func (rd *RealDebrid) GetTorrentInfo(id string) (*TorrentInfo, error) {
return nil, err
}
rd.log.Debugf("Fetched info for torrent id=%s", response.ID)
return &response, nil
}
@@ -178,7 +177,7 @@ func (rd *RealDebrid) SelectTorrentFiles(id string, files string) error {
}
defer resp.Body.Close()
rd.log.Debugf("Selected files %s for torrent id=%s", len(strings.Split(files, ",")), id)
rd.log.Debugf("Selected files %d for torrent id=%s", len(strings.Split(files, ",")), id)
return nil
}

View File

@@ -8,10 +8,15 @@ import (
)
func (rd *RealDebrid) UnrestrictUntilOk(link string) *UnrestrictResponse {
unrestrictFn := func() (*UnrestrictResponse, error) {
if link == "" {
return nil
}
unrestrictFn := func(link string) (*UnrestrictResponse, error) {
return rd.UnrestrictLink(link)
}
return retryUntilOk(unrestrictFn)
return retryUntilOk(func() (*UnrestrictResponse, error) {
return unrestrictFn(link)
})
}
func retryUntilOk[T any](fn func() (T, error)) T {