Skip to content

Commit 508ac2a

Browse files
authored
fix: Improve error handling in file download API (#11127)
1 parent 997b820 commit 508ac2a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

agent/app/api/v2/file.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,14 @@ func (b *BaseApi) Download(c *gin.Context) {
525525
file, err := os.Open(filePath)
526526
if err != nil {
527527
helper.InternalServer(c, err)
528+
return
528529
}
529530
defer file.Close()
530-
info, _ := file.Stat()
531+
info, err := file.Stat()
532+
if err != nil {
533+
helper.InternalServer(c, err)
534+
return
535+
}
531536
c.Header("Content-Length", strconv.FormatInt(info.Size(), 10))
532537
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(info.Name()))
533538
http.ServeContent(c.Writer, c.Request, info.Name(), info.ModTime(), file)

0 commit comments

Comments
 (0)