From a1808a64ccbbe473ea8a69a0e795137e6e1487a8 Mon Sep 17 00:00:00 2001 From: keven1024 Date: Mon, 6 Apr 2026 12:08:23 +0800 Subject: [PATCH] fix(backend): improve error handling in DownloadShare by consolidating token validation and share info retrieval --- backend/internal/controllers/download.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/internal/controllers/download.go b/backend/internal/controllers/download.go index 6e17a56..f1f4624 100644 --- a/backend/internal/controllers/download.go +++ b/backend/internal/controllers/download.go @@ -28,17 +28,13 @@ func DownloadShare(c *echo.Context) error { t, err := jwt.ParseWithClaims(token, &claims, func(token *jwt.Token) (interface{}, error) { return []byte(u.GetEnv("share.download_secret")), nil }) - if err != nil { - return utils.HTTPErrorHandler(c, err) + if err != nil || !t.Valid { + return utils.HTTPErrorHandler(c, lo.Ternary(err != nil, err, ErrInvalidRequest)) } - if !t.Valid { - return utils.HTTPErrorHandler(c, ErrInvalidRequest) + shareInfo, err := models.GetRedisShareInfo(claims.ShareId) + if err != nil || shareInfo == nil { + return utils.HTTPErrorHandler(c, lo.Ternary(err != nil, err, ErrShareNotFound)) } - shareInfo, _ := models.GetRedisShareInfo(claims.ShareId) - if shareInfo == nil { - return utils.HTTPErrorHandler(c, ErrShareNotFound) - } - if shareInfo.Type == models.ShareTypeFile { fileInfo, _ := models.GetRedisFileInfo(shareInfo.Data) uploadPath, err := u.GetUploadDirPath()