From 508ac2ae845fa2f0547f09cf11f05e4d8f94664b Mon Sep 17 00:00:00 2001 From: KOMATA <20227709+HynoR@users.noreply.github.com> Date: Mon, 1 Dec 2025 09:40:48 +0800 Subject: [PATCH] fix: Improve error handling in file download API (#11127) --- agent/app/api/v2/file.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/agent/app/api/v2/file.go b/agent/app/api/v2/file.go index 1e4bdacec..ffa4972f5 100644 --- a/agent/app/api/v2/file.go +++ b/agent/app/api/v2/file.go @@ -525,9 +525,14 @@ func (b *BaseApi) Download(c *gin.Context) { file, err := os.Open(filePath) if err != nil { helper.InternalServer(c, err) + return } defer file.Close() - info, _ := file.Stat() + info, err := file.Stat() + if err != nil { + helper.InternalServer(c, err) + return + } c.Header("Content-Length", strconv.FormatInt(info.Size(), 10)) c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name())) http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)