@@ -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
200197func (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