From fed5e76e7fc94f370cdf1e43d902668e88fbb5f8 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 7 Jul 2022 18:02:07 +0300 Subject: [PATCH] [#1590] node: Check status of forwarded requests After fixing version fields in forwarded requests, a node does not check statuses since errors are not covered by direct call error checks. Signed-off-by: Pavel Karpy --- pkg/services/object/get/v2/util.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index 55933b67c..01c5ce47c 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -15,12 +15,14 @@ import ( rpcclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/signature" + "github.com/nspcc-dev/neofs-api-go/v2/status" "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/network" objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" "github.com/nspcc-dev/neofs-node/pkg/services/object/internal" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -133,6 +135,10 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre return nil, fmt.Errorf("response verification failed: %w", err) } + if err = checkStatus(resp.GetMetaHeader().GetStatus()); err != nil { + return nil, err + } + switch v := resp.GetBody().GetObjectPart().(type) { default: return nil, fmt.Errorf("unexpected object part %T", v) @@ -269,6 +275,10 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get return nil, fmt.Errorf("could not verify %T: %w", resp, err) } + if err = checkStatus(resp.GetMetaHeader().GetStatus()); err != nil { + return nil, err + } + switch v := resp.GetBody().GetRangePart().(type) { case nil: return nil, fmt.Errorf("unexpected range type %T", v) @@ -442,6 +452,10 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp return nil, fmt.Errorf("response verification failed: %w", err) } + if err = checkStatus(resp.GetMetaHeader().GetStatus()); err != nil { + return nil, err + } + var ( hdr *objectV2.Header idSig *refs.Signature @@ -621,3 +635,12 @@ func writeCurrentVersion(metaHdr *session.RequestMetaHeader) { metaHdr.SetVersion(versionV2) } + +func checkStatus(stV2 *status.Status) error { + if !status.IsSuccess(stV2.Code()) { + st := apistatus.FromStatusV2(stV2) + return apistatus.ErrFromStatus(st) + } + + return nil +}