Skip to content

Commit f93d1a5

Browse files
committed
minor cleanup
1 parent 2a4f09c commit f93d1a5

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/debrid/store/download_link.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string
184184
c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link")
185185
return
186186
}
187-
c.client.DeleteDownloadLink(account, downloadLink)
187+
188+
if err := c.client.DeleteDownloadLink(account, downloadLink); err != nil {
189+
c.logger.Error().Err(err).Str("token", utils.Mask(downloadLink.Token)).Msg("Failed to delete download link from account")
190+
return
191+
}
188192
}
189193
}
190194

pkg/debrid/store/stream.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t
104104
}
105105

106106
if streamErr.LinkError {
107-
c.logger.Trace().
108-
Int("retries", retry).
109-
Msg("Link error, getting fresh link")
110107
lastErr = streamErr
111108
// Try new link
112109
downloadLink, err = linkFunc()
@@ -116,7 +113,7 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t
116113
continue
117114
}
118115

119-
// Retryable HTTP error (429, 503, etc.) - retry network
116+
// Retryable HTTP error (429, 503, 404 etc.) - retry network
120117
lastErr = streamErr
121118
c.logger.Trace().
122119
Err(lastErr).
@@ -198,9 +195,6 @@ func (c *Cache) doRequest(ctx context.Context, url string, start, end int64) (*h
198195
}
199196

200197
func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.DownloadLink) StreamError {
201-
body, _ := io.ReadAll(resp.Body)
202-
bodyStr := strings.ToLower(string(body))
203-
204198
switch resp.StatusCode {
205199
case http.StatusNotFound:
206200
c.MarkLinkAsInvalid(downloadLink, "link_not_found")
@@ -211,6 +205,8 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download
211205
}
212206

213207
case http.StatusServiceUnavailable:
208+
body, _ := io.ReadAll(resp.Body)
209+
bodyStr := strings.ToLower(string(body))
214210
if strings.Contains(bodyStr, "bandwidth") || strings.Contains(bodyStr, "traffic") {
215211
c.MarkLinkAsInvalid(downloadLink, "bandwidth_exceeded")
216212
return StreamError{
@@ -230,6 +226,7 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download
230226

231227
default:
232228
retryable := resp.StatusCode >= 500
229+
body, _ := io.ReadAll(resp.Body)
233230
return StreamError{
234231
Err: fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body)),
235232
Retryable: retryable,

0 commit comments

Comments
 (0)