diff --git a/client/common.go b/client/common.go index 1a73303..aa1d042 100644 --- a/client/common.go +++ b/client/common.go @@ -58,7 +58,8 @@ type processResponseV2Res struct { // // Actions: // * verify signature (internal); -// * call response callback (internal). +// * call response callback (internal); +// * unwrap status error (optional). func (c *Client) processResponseV2(res *processResponseV2Res, prm processResponseV2Prm) bool { // verify response structure if isInvalidSignatureV2(res, prm.resp) { @@ -71,10 +72,18 @@ func (c *Client) processResponseV2(res *processResponseV2Res, prm processRespons return true } - // set result status + // get result status st := apistatus.FromStatusV2(prm.resp.GetMetaHeader().GetStatus()) + // unwrap unsuccessful status and return it + // as error if client has been configured so + unsuccessfulStatus := !apistatus.IsSuccessful(st) + if unsuccessfulStatus && c.opts.parseNeoFSErrors { + res.cliErr = apistatus.ErrFromStatus(st) + return true + } + res.statusRes.setStatus(st) - return !apistatus.IsSuccessful(st) + return unsuccessfulStatus } diff --git a/client/opts.go b/client/opts.go index 7986a7b..60a3894 100644 --- a/client/opts.go +++ b/client/opts.go @@ -35,6 +35,12 @@ type ( rawOpts []client.Option cbRespInfo func(ResponseMetaInfo) error + + // defines if client parses erroneous NeoFS + // statuses and returns them as `error` + // + // default is false + parseNeoFSErrors bool } v2SessionReqInfo struct { @@ -195,3 +201,12 @@ func WithGRPCConnection(grpcConn *grpc.ClientConn) Option { opts.rawOpts = append(opts.rawOpts, client.WithGRPCConn(grpcConn)) } } + +// WithNeoFSErrorParsing returns option that makes client parse +// erroneous NeoFS statuses and return them as `error` of the method +// call. +func WithNeoFSErrorParsing() Option { + return func(opts *clientOptions) { + opts.parseNeoFSErrors = true + } +}