[server] Sending 204 instead of 404 for no data (#5880)
## Description ## Tests
This commit is contained in:
@@ -63,8 +63,9 @@ func (g *GetFilesData) Validate() error {
|
||||
}
|
||||
|
||||
type GetFileData struct {
|
||||
FileID int64 `form:"fileID" binding:"required"`
|
||||
Type ente.ObjectType `form:"type" binding:"required"`
|
||||
FileID int64 `form:"fileID" binding:"required"`
|
||||
Type ente.ObjectType `form:"type" binding:"required"`
|
||||
PreferNoContent bool `form:"preferNoContent"`
|
||||
}
|
||||
|
||||
func (g *GetFileData) Validate() error {
|
||||
|
||||
@@ -109,6 +109,10 @@ func (h *FileHandler) GetFileData(ctx *gin.Context) {
|
||||
handler.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
if resp == nil {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"data": resp,
|
||||
})
|
||||
|
||||
@@ -79,6 +79,10 @@ func (h *PublicCollectionHandler) GetFileData(c *gin.Context) {
|
||||
handler.Error(c, err)
|
||||
return
|
||||
}
|
||||
if resp == nil {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": resp,
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ package filedata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
@@ -138,6 +139,9 @@ func (c *Controller) GetFileData(ctx *gin.Context, actorUser int64, req fileData
|
||||
}
|
||||
doRows, err := c.Repo.GetFilesData(ctx, req.Type, []int64{req.FileID})
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) && req.PreferNoContent {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
if len(doRows) == 0 || doRows[0].IsDeleted {
|
||||
|
||||
Reference in New Issue
Block a user