Skip to content

Commit

Permalink
handler: Return 500 instead of 404 for general error
Browse files Browse the repository at this point in the history
Closes #250.

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Oct 22, 2024
1 parent 23424c7 commit 90b8fc4
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(http.StatusInternalServerError, resp)

Check warning on line 230 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L230

Added line #L230 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 250 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L250

Added line #L250 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 290 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L290

Added line #L290 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 310 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L310

Added line #L310 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 1047 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1047

Added line #L1047 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 1067 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1067

Added line #L1067 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 1102 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1102

Added line #L1102 was not covered by tests
}

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(http.StatusInternalServerError, resp)

Check warning on line 1122 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1122

Added line #L1122 was not covered by tests
}

var addrObj oid.Address
Expand Down

0 comments on commit 90b8fc4

Please sign in to comment.