enhancement: add error origin information to the errorcode package
This commit is contained in:
@@ -17,12 +17,6 @@ import (
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
roleconversions "github.com/cs3org/reva/v2/pkg/conversions"
|
||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
|
||||
"github.com/go-chi/chi/v5"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -31,6 +25,13 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
roleconversions "github.com/cs3org/reva/v2/pkg/conversions"
|
||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
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/config/defaults"
|
||||
@@ -249,7 +250,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
|
||||
statResponse.Status = status.NewNotFound(context.Background(), "not found")
|
||||
permission, err := driveItemPermissionsService.Invite(context.Background(), driveItemId, driveItemInvite)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.ItemNotFound, "not found")))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.ItemNotFound, "not found").WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
Expect(permission).To(BeZero())
|
||||
})
|
||||
})
|
||||
@@ -999,7 +1000,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
|
||||
|
||||
driveItemPermission.SetExpirationDateTime(expiration)
|
||||
res, err := driveItemPermissionsService.UpdatePermission(context.Background(), driveItemId, "permissionid", driveItemPermission)
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.InvalidRequest, "expiration date is in the past")))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.InvalidRequest, "expiration date is in the past").WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
Expect(res).To(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -360,7 +360,7 @@ func (api DrivesDriveItemApi) DeleteDriveItem(w http.ResponseWriter, r *http.Req
|
||||
|
||||
shareID := ExtractShareIdFromResourceId(itemID)
|
||||
if err := api.drivesDriveItemService.UnmountShare(ctx, shareID); err != nil {
|
||||
api.logger.Debug().Err(err).Msg(err.Error())
|
||||
api.logger.Debug().Err(err).Msg(ErrUnmountShare.Error())
|
||||
errorcode.RenderError(w, r, err)
|
||||
return
|
||||
}
|
||||
@@ -518,8 +518,15 @@ func (api DrivesDriveItemApi) CreateDriveItem(w http.ResponseWriter, r *http.Req
|
||||
|
||||
mountedShares, err := api.drivesDriveItemService.MountShare(ctx, &resourceId, requestDriveItem.GetName())
|
||||
if err != nil {
|
||||
api.logger.Debug().Err(err).Msg(err.Error())
|
||||
errorcode.RenderError(w, r, err)
|
||||
api.logger.Debug().Err(err).Msg(ErrMountShare.Error())
|
||||
|
||||
switch e, ok := errorcode.ToError(err); {
|
||||
case ok && e.GetOrigin() == errorcode.ErrorOriginCS3 && e.GetCode() == errorcode.ItemNotFound:
|
||||
ErrDriveItemConversion.Render(w, r)
|
||||
default:
|
||||
errorcode.RenderError(w, r, err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
Once()
|
||||
|
||||
_, err := drivesDriveItemService.GetShare(context.Background(), &collaborationv1beta1.ShareId{})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
})
|
||||
|
||||
It("fails if share lookup does not report an error but the status is off", func() {
|
||||
@@ -161,12 +161,12 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
EXPECT().
|
||||
GetReceivedShare(context.Background(), mock.Anything, mock.Anything).
|
||||
Return(&collaborationv1beta1.GetReceivedShareResponse{
|
||||
Status: status.NewNotFound(context.Background(), someErr.Error()),
|
||||
Status: status.NewInvalid(context.Background(), someErr.Error()),
|
||||
}, nil).
|
||||
Once()
|
||||
|
||||
_, err := drivesDriveItemService.GetShare(context.Background(), &collaborationv1beta1.ShareId{})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.ItemNotFound, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.InvalidRequest, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
})
|
||||
|
||||
It("successfully returns a share", func() {
|
||||
@@ -219,7 +219,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
request.Share.State = collaborationv1beta1.ShareState_SHARE_STATE_ACCEPTED
|
||||
request.UpdateMask.Paths = append(request.UpdateMask.Paths, "state")
|
||||
})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
})
|
||||
|
||||
It("fails if share update does not report an error but the status is off", func() {
|
||||
@@ -236,7 +236,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
request.Share.State = collaborationv1beta1.ShareState_SHARE_STATE_ACCEPTED
|
||||
request.UpdateMask.Paths = append(request.UpdateMask.Paths, "state")
|
||||
})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.ItemNotFound, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.ItemNotFound, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -265,7 +265,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
request.Share.State = collaborationv1beta1.ShareState_SHARE_STATE_ACCEPTED
|
||||
request.UpdateMask.Paths = append(request.UpdateMask.Paths, "state")
|
||||
})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
Expect(err.(interface{ Unwrap() []error }).Unwrap()).To(HaveLen(2))
|
||||
Expect(shares).To(HaveLen(1))
|
||||
})
|
||||
@@ -281,7 +281,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
Once()
|
||||
|
||||
err := drivesDriveItemService.UnmountShare(context.Background(), &collaborationv1beta1.ShareId{})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
})
|
||||
|
||||
It("requests only accepted shares to be unmounted", func() {
|
||||
@@ -358,7 +358,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
Times(1)
|
||||
|
||||
err := drivesDriveItemService.UnmountShare(context.Background(), &collaborationv1beta1.ShareId{})
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
Expect(err.(interface{ Unwrap() []error }).Unwrap()).To(HaveLen(1))
|
||||
})
|
||||
})
|
||||
@@ -436,7 +436,7 @@ var _ = Describe("DrivesDriveItemService", func() {
|
||||
Times(3)
|
||||
|
||||
shares, err := drivesDriveItemService.MountShare(context.Background(), nil, "some")
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error())))
|
||||
Expect(err).To(MatchError(errorcode.New(errorcode.GeneralException, someErr.Error()).WithOrigin(errorcode.ErrorOriginCS3)))
|
||||
Expect(err.(interface{ Unwrap() []error }).Unwrap()).To(HaveLen(3))
|
||||
Expect(shares).To(HaveLen(0))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user