fix: explicitly ignore Close() errors in error paths and retry loops

This commit is contained in:
程智超0668000959
2026-06-25 15:38:41 +08:00
parent dff16dbb91
commit 62a2b0015a
4 changed files with 22 additions and 22 deletions
+2 -2
View File
@@ -26,7 +26,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
for i := range maxRetries {
if i > 0 && resp != nil {
resp.Body.Close()
_ = resp.Body.Close()
}
resp, err = client.Do(req)
@@ -42,7 +42,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
if i < maxRetries-1 {
if err = sleepWithCtx(req.Context(), retryDelayForAttempt(resp, i)); err != nil {
if resp != nil {
resp.Body.Close()
_ = resp.Body.Close()
}
return nil, fmt.Errorf("failed to sleep: %w", err)
}
+1 -1
View File
@@ -176,7 +176,7 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string {
}
if _, err := io.Copy(out, resp.Body); err != nil {
out.Close()
_ = out.Close()
os.Remove(localPath)
logger.ErrorCF(opts.LoggerPrefix, "Failed to write file", map[string]any{
"error": err.Error(),