Skip to content

Commit

Permalink
Merge pull request #252 from nspcc-dev/250-must-not-return-404-in-cas…
Browse files Browse the repository at this point in the history
…e-of-error

Return 500 instead of 404 for general error
  • Loading branch information
roman-khimov authored Oct 25, 2024
2 parents d6fe7f8 + 3d204e8 commit 84bdfa8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions handlers/newObjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (a *RestAPI) NewGetByAttribute(ctx echo.Context, containerID apiserver.Cont
res, err := a.search(ctx.Request().Context(), btoken, cnrID, attrKey, attrVal, object.MatchStringEqual)
if err != nil {
resp := a.logAndGetErrorResponse("could not search for objects", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

defer func() {
Expand All @@ -247,7 +247,7 @@ func (a *RestAPI) NewGetByAttribute(ctx echo.Context, containerID apiserver.Cont
}

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

var addrObj oid.Address
Expand Down Expand Up @@ -287,7 +287,7 @@ func (a *RestAPI) NewHeadByAttribute(ctx echo.Context, containerID apiserver.Con
res, err := a.search(ctx.Request().Context(), btoken, cnrID, attrKey, attrVal, object.MatchStringEqual)
if err != nil {
resp := a.logAndGetErrorResponse("could not search for objects", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

defer func() {
Expand All @@ -307,7 +307,7 @@ func (a *RestAPI) NewHeadByAttribute(ctx echo.Context, containerID apiserver.Con
}

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

var addrObj oid.Address
Expand Down
8 changes: 4 additions & 4 deletions handlers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ func (a *RestAPI) GetByAttribute(ctx echo.Context, containerID apiserver.Contain
res, err := a.search(ctx.Request().Context(), btoken, cnrID, attrKey, attrVal, object.MatchStringEqual)
if err != nil {
resp := a.logAndGetErrorResponse("could not search for objects", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

defer func() {
Expand All @@ -1064,7 +1064,7 @@ func (a *RestAPI) GetByAttribute(ctx echo.Context, containerID apiserver.Contain
}

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

var addrObj oid.Address
Expand Down Expand Up @@ -1099,7 +1099,7 @@ func (a *RestAPI) HeadByAttribute(ctx echo.Context, containerID apiserver.Contai
res, err := a.search(ctx.Request().Context(), btoken, cnrID, attrKey, attrVal, object.MatchStringEqual)
if err != nil {
resp := a.logAndGetErrorResponse("could not search for objects", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

defer func() {
Expand All @@ -1119,7 +1119,7 @@ func (a *RestAPI) HeadByAttribute(ctx echo.Context, containerID apiserver.Contai
}

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
return ctx.JSON(getResponseCodeFromStatus(err), resp)
}

var addrObj oid.Address
Expand Down

0 comments on commit 84bdfa8

Please sign in to comment.