fix: 文件不存在时提供报错信息

getFileUrlLogic 捕获 S3 NotFound 返回语义明确的错误信息,
getFileLogic 将 gRPC 错误转为普通 error 避免 HTTP 500。
This commit is contained in:
zetaloop
2026-04-05 19:23:43 +08:00
parent 3f306cf0a9
commit 28b48736af
2 changed files with 7 additions and 1 deletions
@@ -9,6 +9,7 @@ import (
"juwan-backend/app/objectstory/rpc/pb"
"github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -37,6 +38,10 @@ func (l *GetFileUrlLogic) GetFileUrl(in *pb.GetFileUrlReq) (*pb.GetFileUrlResp,
Key: &in.FileId,
})
if err != nil {
var nf *s3types.NotFound
if errors.As(err, &nf) {
return nil, errors.New("file not found")
}
return nil, err
}