From f93d1a591340785725b4d931a847698db4ee2fd3 Mon Sep 17 00:00:00 2001 From: Mukhtar Akere Date: Thu, 16 Oct 2025 21:04:14 +0100 Subject: [PATCH] minor cleanup --- pkg/debrid/store/download_link.go | 6 +++++- pkg/debrid/store/stream.go | 11 ++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/debrid/store/download_link.go b/pkg/debrid/store/download_link.go index 032614f..591b6a1 100644 --- a/pkg/debrid/store/download_link.go +++ b/pkg/debrid/store/download_link.go @@ -184,7 +184,11 @@ func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link") return } - c.client.DeleteDownloadLink(account, downloadLink) + + if err := c.client.DeleteDownloadLink(account, downloadLink); err != nil { + c.logger.Error().Err(err).Str("token", utils.Mask(downloadLink.Token)).Msg("Failed to delete download link from account") + return + } } } diff --git a/pkg/debrid/store/stream.go b/pkg/debrid/store/stream.go index fcff288..7e4c070 100644 --- a/pkg/debrid/store/stream.go +++ b/pkg/debrid/store/stream.go @@ -104,9 +104,6 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t } if streamErr.LinkError { - c.logger.Trace(). - Int("retries", retry). - Msg("Link error, getting fresh link") lastErr = streamErr // Try new link downloadLink, err = linkFunc() @@ -116,7 +113,7 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t continue } - // Retryable HTTP error (429, 503, etc.) - retry network + // Retryable HTTP error (429, 503, 404 etc.) - retry network lastErr = streamErr c.logger.Trace(). Err(lastErr). @@ -198,9 +195,6 @@ func (c *Cache) doRequest(ctx context.Context, url string, start, end int64) (*h } func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.DownloadLink) StreamError { - body, _ := io.ReadAll(resp.Body) - bodyStr := strings.ToLower(string(body)) - switch resp.StatusCode { case http.StatusNotFound: c.MarkLinkAsInvalid(downloadLink, "link_not_found") @@ -211,6 +205,8 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download } case http.StatusServiceUnavailable: + body, _ := io.ReadAll(resp.Body) + bodyStr := strings.ToLower(string(body)) if strings.Contains(bodyStr, "bandwidth") || strings.Contains(bodyStr, "traffic") { c.MarkLinkAsInvalid(downloadLink, "bandwidth_exceeded") return StreamError{ @@ -230,6 +226,7 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download default: retryable := resp.StatusCode >= 500 + body, _ := io.ReadAll(resp.Body) return StreamError{ Err: fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body)), Retryable: retryable,