From 90b8fc405b694b5cbd911f414da2ea6b567f7713 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Tue, 22 Oct 2024 13:46:26 +0400 Subject: [PATCH] handler: Return 500 instead of 404 for general 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 00fbab5..2800067 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, resp) } var addrObj oid.Address diff --git a/handlers/objects.go b/handlers/objects.go index 2005aa8..3b9ae02 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, 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(http.StatusInternalServerError, resp) } var addrObj oid.Address