From 3d204e8f1e11ef6d9e6ae921a7231101d069aba1 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Fri, 25 Oct 2024 09:00:09 +0400 Subject: [PATCH] handler: Return http code according to the NeoFS error Closes #250. Signed-off-by: Evgenii Baidakov --- handlers/newObjects.go | 8 ++++---- handlers/objects.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/handlers/newObjects.go b/handlers/newObjects.go index 68d5ae6..7707998 100644 --- a/handlers/newObjects.go +++ b/handlers/newObjects.go @@ -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() { @@ -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 @@ -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() { @@ -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 diff --git a/handlers/objects.go b/handlers/objects.go index a11086c..4e584e7 100644 --- a/handlers/objects.go +++ b/handlers/objects.go @@ -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() { @@ -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 @@ -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() { @@ -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