handle errors in defer close

This commit is contained in:
2026-05-07 08:56:38 -06:00
parent c565a2d97a
commit 0eedf23667
3 changed files with 15 additions and 5 deletions
+5 -1
View File
@@ -41,7 +41,11 @@ func (s *Server) handlerPackage(w http.ResponseWriter, req *http.Request) {
http.Error(w, "Failed to fetch from upstream", http.StatusBadGateway)
return
}
defer cachedFile.Reader.Close()
defer func() {
if closeErr := cachedFile.Reader.Close(); closeErr != nil {
err = closeErr
}
}()
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename="+cachedFile.Filename)