mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix: check Close() error after downloading media file
This commit is contained in:
+7
-1
@@ -146,7 +146,6 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string {
|
||||
})
|
||||
return ""
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||
out.Close()
|
||||
@@ -156,6 +155,13 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string {
|
||||
})
|
||||
return ""
|
||||
}
|
||||
if err := out.Close(); err != nil {
|
||||
logger.ErrorCF(opts.LoggerPrefix, "Failed to close downloaded file", map[string]any{
|
||||
"error": err.Error(),
|
||||
})
|
||||
os.Remove(localPath)
|
||||
return ""
|
||||
}
|
||||
|
||||
logger.DebugCF(opts.LoggerPrefix, "File downloaded successfully", map[string]any{
|
||||
"path": localPath,
|
||||
|
||||
Reference in New Issue
Block a user