Skip to content

Commit

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

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Oct 23, 2024
1 parent 23424c7 commit 6bc56b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
24 changes: 20 additions & 4 deletions handlers/newObjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ 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)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 232 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L230-L232

Added lines #L230 - L232 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 234 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L234

Added line #L234 was not covered by tests
}

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

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 256 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L254-L256

Added lines #L254 - L256 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 258 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L258

Added line #L258 was not covered by tests
}

var addrObj oid.Address
Expand Down Expand Up @@ -287,7 +295,11 @@ 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)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 300 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L298-L300

Added lines #L298 - L300 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 302 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L302

Added line #L302 was not covered by tests
}

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

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 324 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L322-L324

Added lines #L322 - L324 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 326 in handlers/newObjects.go

View check run for this annotation

Codecov / codecov/patch

handlers/newObjects.go#L326

Added line #L326 was not covered by tests
}

var addrObj oid.Address
Expand Down
24 changes: 20 additions & 4 deletions handlers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,11 @@ 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)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 1049 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1047-L1049

Added lines #L1047 - L1049 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 1051 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1051

Added line #L1051 was not covered by tests
}

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

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 1073 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1071-L1073

Added lines #L1071 - L1073 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 1075 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1075

Added line #L1075 was not covered by tests
}

var addrObj oid.Address
Expand Down Expand Up @@ -1099,7 +1107,11 @@ 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)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 1112 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1110-L1112

Added lines #L1110 - L1112 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 1114 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1114

Added line #L1114 was not covered by tests
}

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

resp := a.logAndGetErrorResponse("read object list failed", err)
return ctx.JSON(http.StatusNotFound, resp)
if strings.Contains(err.Error(), "code = 1024") {
return ctx.JSON(http.StatusBadGateway, resp)
}

Check warning on line 1136 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1134-L1136

Added lines #L1134 - L1136 were not covered by tests

return ctx.JSON(http.StatusInternalServerError, resp)

Check warning on line 1138 in handlers/objects.go

View check run for this annotation

Codecov / codecov/patch

handlers/objects.go#L1138

Added line #L1138 was not covered by tests
}

var addrObj oid.Address
Expand Down

0 comments on commit 6bc56b6

Please sign in to comment.