Skip to content

Commit

Permalink
always use error interface when returning errors (#8816)
Browse files Browse the repository at this point in the history
* always use error interface when returning errors

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* fix: use non pointer Error

* fix: errorcode evaluation

---------

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Co-authored-by: Florian Schade <[email protected]>
  • Loading branch information
butonic and fschade authored Apr 12, 2024
1 parent fad37db commit 7a63573
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 90 deletions.
12 changes: 6 additions & 6 deletions services/graph/pkg/errorcode/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
//
// This function is particularly useful when dealing with CS3 responses,
// and a unified error handling within the application is necessary.
func FromCS3Status(status *cs3rpc.Status, inerr error, ignore ...cs3rpc.Code) *Error {
func FromCS3Status(status *cs3rpc.Status, inerr error, ignore ...cs3rpc.Code) error {
if inerr != nil {
return &Error{msg: inerr.Error(), errorCode: GeneralException}
return Error{msg: inerr.Error(), errorCode: GeneralException}
}

err := &Error{errorCode: GeneralException, msg: "unspecified error has occurred"}
err := Error{errorCode: GeneralException, msg: "unspecified error has occurred"}

if status != nil {
err.msg = status.GetMessage()
Expand All @@ -33,7 +33,7 @@ func FromCS3Status(status *cs3rpc.Status, inerr error, ignore ...cs3rpc.Code) *E
case slices.Contains(ignore, status.GetCode()):
fallthrough
case code == cs3rpc.Code_CODE_OK:
err = nil
return nil
case code == cs3rpc.Code_CODE_NOT_FOUND:
err.errorCode = ItemNotFound
case code == cs3rpc.Code_CODE_PERMISSION_DENIED:
Expand Down Expand Up @@ -61,11 +61,11 @@ func FromCS3Status(status *cs3rpc.Status, inerr error, ignore ...cs3rpc.Code) *E
return err
}

// FromStat transforms a *provider.StatResponse object and an error into an *Error.
// FromStat transforms a *provider.StatResponse object and an error into an Error.
//
// It takes a stat of type *provider.StatResponse, an error, and a variadic parameter of type cs3rpc.Code.
// It invokes the FromCS3Status function with the StatResponse Status and the ignore codes.
func FromStat(stat *provider.StatResponse, err error, ignore ...cs3rpc.Code) *Error {
func FromStat(stat *provider.StatResponse, err error, ignore ...cs3rpc.Code) error {
// TODO: look into ResourceInfo to get the postprocessing state and map that to 425 status?
return FromCS3Status(stat.GetStatus(), err, ignore...)
}
57 changes: 28 additions & 29 deletions services/graph/pkg/errorcode/cs3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,44 @@ import (
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"

"github.com/owncloud/ocis/v2/ocis-pkg/conversions"
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
)

func TestFromCS3Status(t *testing.T) {
var tests = []struct {
status *cs3rpc.Status
err error
ignore []cs3rpc.Code
result *errorcode.Error
status *cs3rpc.Status
err error
ignore []cs3rpc.Code
expected error
}{
{nil, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "unspecified error has occurred"))},
{nil, errors.New("test error"), nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "test error"))},
{nil, nil, nil, errorcode.New(errorcode.GeneralException, "unspecified error has occurred")},
{nil, errors.New("test error"), nil, errorcode.New(errorcode.GeneralException, "test error")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_OK}, nil, nil, nil},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_NOT_FOUND}, nil, []cs3rpc.Code{cs3rpc.Code_CODE_NOT_FOUND}, nil},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_PERMISSION_DENIED}, nil, []cs3rpc.Code{cs3rpc.Code_CODE_NOT_FOUND, cs3rpc.Code_CODE_PERMISSION_DENIED}, nil},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_NOT_FOUND, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.ItemNotFound, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_PERMISSION_DENIED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.AccessDenied, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNAUTHENTICATED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.Unauthenticated, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INVALID_ARGUMENT, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.InvalidRequest, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_ALREADY_EXISTS, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.NameAlreadyExists, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_FAILED_PRECONDITION, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.InvalidRequest, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNIMPLEMENTED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.NotSupported, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INVALID, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_CANCELLED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNKNOWN, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_RESOURCE_EXHAUSTED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_ABORTED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_OUT_OF_RANGE, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.InvalidRange, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INTERNAL, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNAVAILABLE, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.ServiceNotAvailable, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_REDIRECTION, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.GeneralException, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INSUFFICIENT_STORAGE, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.QuotaLimitReached, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_LOCKED, Message: "msg"}, nil, nil, conversions.ToPointer(errorcode.New(errorcode.ItemIsLocked, "msg"))},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_NOT_FOUND, Message: "msg"}, nil, nil, errorcode.New(errorcode.ItemNotFound, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_PERMISSION_DENIED, Message: "msg"}, nil, nil, errorcode.New(errorcode.AccessDenied, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNAUTHENTICATED, Message: "msg"}, nil, nil, errorcode.New(errorcode.Unauthenticated, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INVALID_ARGUMENT, Message: "msg"}, nil, nil, errorcode.New(errorcode.InvalidRequest, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_ALREADY_EXISTS, Message: "msg"}, nil, nil, errorcode.New(errorcode.NameAlreadyExists, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_FAILED_PRECONDITION, Message: "msg"}, nil, nil, errorcode.New(errorcode.InvalidRequest, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNIMPLEMENTED, Message: "msg"}, nil, nil, errorcode.New(errorcode.NotSupported, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INVALID, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_CANCELLED, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNKNOWN, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_RESOURCE_EXHAUSTED, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_ABORTED, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_OUT_OF_RANGE, Message: "msg"}, nil, nil, errorcode.New(errorcode.InvalidRange, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INTERNAL, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_UNAVAILABLE, Message: "msg"}, nil, nil, errorcode.New(errorcode.ServiceNotAvailable, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_REDIRECTION, Message: "msg"}, nil, nil, errorcode.New(errorcode.GeneralException, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_INSUFFICIENT_STORAGE, Message: "msg"}, nil, nil, errorcode.New(errorcode.QuotaLimitReached, "msg")},
{&cs3rpc.Status{Code: cs3rpc.Code_CODE_LOCKED, Message: "msg"}, nil, nil, errorcode.New(errorcode.ItemIsLocked, "msg")},
}

for _, test := range tests {
if output := errorcode.FromCS3Status(test.status, test.err, test.ignore...); !reflect.DeepEqual(output, test.result) {
t.Error("Test Failed: {} expected, received: {}", test.result, output)
if got := errorcode.FromCS3Status(test.status, test.err, test.ignore...); !reflect.DeepEqual(got, test.expected) {
t.Error("Test Failed: {} expected, received: {}", test.expected, got)
}
}
}
Expand All @@ -55,9 +54,9 @@ func TestFromStat(t *testing.T) {
var tests = []struct {
stat *provider.StatResponse
err error
result *errorcode.Error
result error
}{
{nil, errors.New("some error"), conversions.ToPointer(errorcode.New(errorcode.GeneralException, "some error"))},
{nil, errors.New("some error"), errorcode.New(errorcode.GeneralException, "some error")},
{&provider.StatResponse{Status: &cs3rpc.Status{Code: cs3rpc.Code_CODE_OK}}, nil, nil},
}

Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/errorcode/errorcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ func RenderError(w http.ResponseWriter, r *http.Request, err error) {
var errcode Error
if errors.As(err, &errcode) {
errcode.Render(w, r)
} else {
GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}

GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
}
45 changes: 45 additions & 0 deletions services/graph/pkg/errorcode/errorcode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package errorcode_test

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"

"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
)

type customErr struct{}

func (customErr) Error() string {
return "some error"
}

func TestRenderError(t *testing.T) {
t.Parallel()

t.Run("errorcode.Error value error", func(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
err := errorcode.New(errorcode.ItemNotFound, "test error")
errorcode.RenderError(w, r, err)
require.Equal(t, http.StatusNotFound, w.Code)
})

t.Run("errorcode.Error zero value error", func(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
var err errorcode.Error
errorcode.RenderError(w, r, err)
require.Equal(t, http.StatusForbidden, w.Code)
})

t.Run("custom error", func(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
var err customErr
errorcode.RenderError(w, r, err)
require.Equal(t, http.StatusInternalServerError, w.Code)
})
}
14 changes: 7 additions & 7 deletions services/graph/pkg/service/v0/api_driveitem_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId stor
}

statResponse, err := gatewayClient.Stat(ctx, &storageprovider.StatRequest{Ref: &storageprovider.Reference{ResourceId: &resourceId}})
if errCode := errorcode.FromStat(statResponse, err); errCode != nil {
s.logger.Warn().Err(errCode).Interface("stat.res", statResponse).Msg("stat failed")
return libregraph.Permission{}, *errCode
if err := errorcode.FromStat(statResponse, err); err != nil {
s.logger.Warn().Err(err).Interface("stat.res", statResponse).Msg("stat failed")
return libregraph.Permission{}, err
}

var condition string
Expand Down Expand Up @@ -177,9 +177,9 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId stor
}

createShareResponse, err := gatewayClient.CreateShare(ctx, createShareRequest)
if errCode := errorcode.FromCS3Status(createShareResponse.GetStatus(), err); errCode != nil {
if err := errorcode.FromCS3Status(createShareResponse.GetStatus(), err); err != nil {
s.logger.Debug().Err(err).Msg("share creation failed")
return libregraph.Permission{}, *errCode
return libregraph.Permission{}, err
}

if id := createShareResponse.GetShare().GetId().GetOpaqueId(); id != "" {
Expand Down Expand Up @@ -226,8 +226,8 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
}

statResponse, err := gatewayClient.Stat(ctx, &storageprovider.StatRequest{Ref: &storageprovider.Reference{ResourceId: &itemID}})
if errCode := errorcode.FromStat(statResponse, err); errCode != nil {
s.logger.Warn().Err(errCode).Interface("stat.res", statResponse).Msg("stat failed")
if err := errorcode.FromStat(statResponse, err); err != nil {
s.logger.Warn().Err(err).Interface("stat.res", statResponse).Msg("stat failed")
return collectionOfPermissions, err
}

Expand Down
12 changes: 6 additions & 6 deletions services/graph/pkg/service/v0/api_driveitem_permissions_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ func (s DriveItemPermissionsService) updatePublicLinkPermission(ctx context.Cont
},
})

if errCode := errorcode.FromCS3Status(statResp.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(statResp.GetStatus(), err); err != nil {
return nil, err
}

if newPermission.HasExpirationDateTime() {
Expand Down Expand Up @@ -369,8 +369,8 @@ func (s DriveItemPermissionsService) updatePublicLinkPassword(ctx context.Contex
},
},
})
if errCode := errorcode.FromCS3Status(changeLinkRes.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(changeLinkRes.GetStatus(), err); err != nil {
return nil, err
}
permission, err := s.libreGraphPermissionFromCS3PublicShare(changeLinkRes.GetShare())
if err != nil {
Expand All @@ -396,8 +396,8 @@ func (s DriveItemPermissionsService) updatePublicLink(ctx context.Context, permi
},
})

if errCode := errorcode.FromCS3Status(changeLinkRes.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(changeLinkRes.GetStatus(), err); err != nil {
return nil, err
}

permission, err := s.libreGraphPermissionFromCS3PublicShare(changeLinkRes.GetShare())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/stretchr/testify/mock"
"github.com/tidwall/gjson"
"google.golang.org/grpc"

"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/graph/mocks"
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
Expand All @@ -35,9 +39,6 @@ import (
"github.com/owncloud/ocis/v2/services/graph/pkg/linktype"
svc "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
"github.com/owncloud/ocis/v2/services/graph/pkg/unifiedrole"
"github.com/stretchr/testify/mock"
"github.com/tidwall/gjson"
"google.golang.org/grpc"
)

var _ = Describe("DriveItemPermissionsService", func() {
Expand Down Expand Up @@ -696,7 +697,6 @@ var _ = Describe("DriveItemPermissionsService", func() {
},
},
}

})
It("fails when no share is found", func() {
getShareMockResponse.Share = nil
Expand Down
6 changes: 3 additions & 3 deletions services/graph/pkg/service/v0/api_drives_drive_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (s DrivesDriveItemService) UnmountShare(ctx context.Context, resourceID sto
},
},
)
if errCode := errorcode.FromCS3Status(getReceivedShareResponse.GetStatus(), err); errCode != nil {
s.logger.Debug().Err(errCode).
if err := errorcode.FromCS3Status(getReceivedShareResponse.GetStatus(), err); err != nil {
s.logger.Debug().Err(err).
Str("shareid", shareId).
Msg("failed to read share")
return errCode
return err
}

// Find all accepted shares for this resource
Expand Down
3 changes: 2 additions & 1 deletion services/graph/pkg/service/v0/api_drives_drive_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/pkg/storagespace"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"

"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/graph/mocks"
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
Expand Down Expand Up @@ -377,7 +378,7 @@ var _ = Describe("DrivesDriveItemService", func() {
Return(&collaborationv1beta1.GetReceivedShareResponse{}, errors.New("listing shares failed"))

err := drivesDriveItemService.UnmountShare(context.Background(), storageprovider.ResourceId{})
Expect(err).To(MatchError(&expectedError))
Expect(err).To(MatchError(expectedError))
})

It("uses the correct filters to get the shares", func() {
Expand Down
27 changes: 14 additions & 13 deletions services/graph/pkg/service/v0/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
libregraph "github.com/owncloud/libre-graph-api-go"
"google.golang.org/protobuf/types/known/fieldmaskpb"

"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
"github.com/owncloud/ocis/v2/services/graph/pkg/identity"
"github.com/owncloud/ocis/v2/services/graph/pkg/linktype"
"github.com/owncloud/ocis/v2/services/graph/pkg/unifiedrole"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)

// BaseGraphService implements a couple of helper functions that are
Expand Down Expand Up @@ -424,8 +425,8 @@ func (g BaseGraphService) getCS3PublicShareByID(ctx context.Context, permissionI
},
},
)
if errCode := errorcode.FromCS3Status(getPublicShareResp.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(getPublicShareResp.GetStatus(), err); err != nil {
return nil, err
}
return getPublicShareResp.GetShare(), nil
}
Expand All @@ -447,8 +448,8 @@ func (g BaseGraphService) removePublicShare(ctx context.Context, permissionID st
},
},
})
if errcode := errorcode.FromCS3Status(removePublicShareResp.GetStatus(), err); errcode != nil {
return *errcode
if err := errorcode.FromCS3Status(removePublicShareResp.GetStatus(), err); err != nil {
return err
}
// We need to return an untyped nil here otherwise the error==nil check won't work
return nil
Expand All @@ -472,8 +473,8 @@ func (g BaseGraphService) removeUserShare(ctx context.Context, permissionID stri
},
})

if errCode := errorcode.FromCS3Status(removeShareResp.GetStatus(), err); errCode != nil {
return *errCode
if err := errorcode.FromCS3Status(removeShareResp.GetStatus(), err); err != nil {
return err
}
// We need to return an untyped nil here otherwise the error==nil check won't work
return nil
Expand Down Expand Up @@ -501,8 +502,8 @@ func (g BaseGraphService) removeSpacePermission(ctx context.Context, permissionI
},
})

if errCode := errorcode.FromCS3Status(removeShareResp.GetStatus(), err); errCode != nil {
return *errCode
if err := errorcode.FromCS3Status(removeShareResp.GetStatus(), err); err != nil {
return err
}
// We need to return an untyped nil here otherwise the error==nil check won't work
return nil
Expand Down Expand Up @@ -533,8 +534,8 @@ func (g BaseGraphService) getCS3UserShareByID(ctx context.Context, permissionID
},
},
})
if errCode := errorcode.FromCS3Status(getShareResp.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(getShareResp.GetStatus(), err); err != nil {
return nil, err
}
return getShareResp.GetShare(), nil
}
Expand Down Expand Up @@ -683,8 +684,8 @@ func (g BaseGraphService) updateUserShare(ctx context.Context, permissionID stri
}

updateUserShareResp, err := gatewayClient.UpdateShare(ctx, &cs3UpdateShareReq)
if errCode := errorcode.FromCS3Status(updateUserShareResp.GetStatus(), err); errCode != nil {
return nil, *errCode
if err := errorcode.FromCS3Status(updateUserShareResp.GetStatus(), err); err != nil {
return nil, err
}

permission, err := g.cs3UserShareToPermission(ctx, updateUserShareResp.GetShare(), condition)
Expand Down
Loading

0 comments on commit 7a63573

Please sign in to comment.