diff --git a/changelog/unreleased/ocm-error-handling.md b/changelog/unreleased/ocm-error-handling.md new file mode 100644 index 0000000000..8d45c6ab79 --- /dev/null +++ b/changelog/unreleased/ocm-error-handling.md @@ -0,0 +1,5 @@ +Bugfix: simplified error handling + +Minor rewording and simplification, following cs3org/OCM-API#90 and cs3org/OCM-API#91 + +https://github.com/cs3org/reva/pull/4810 diff --git a/internal/grpc/services/ocminvitemanager/ocminvitemanager.go b/internal/grpc/services/ocminvitemanager/ocminvitemanager.go index a4f0d44039..0474c3cae8 100644 --- a/internal/grpc/services/ocminvitemanager/ocminvitemanager.go +++ b/internal/grpc/services/ocminvitemanager/ocminvitemanager.go @@ -174,11 +174,7 @@ func (s *service) ForwardInvite(ctx context.Context, req *invitepb.ForwardInvite switch { case errors.Is(err, ocmd.ErrTokenInvalid): return &invitepb.ForwardInviteResponse{ - Status: status.NewInvalid(ctx, "token not valid"), - }, nil - case errors.Is(err, ocmd.ErrTokenNotFound): - return &invitepb.ForwardInviteResponse{ - Status: status.NewNotFound(ctx, "token not found"), + Status: status.NewInvalid(ctx, "token not valid or not found"), }, nil case errors.Is(err, ocmd.ErrUserAlreadyAccepted): return &invitepb.ForwardInviteResponse{ @@ -238,9 +234,9 @@ func getOCMEndpoint(originProvider *ocmprovider.ProviderInfo) (string, error) { func (s *service) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteRequest) (*invitepb.AcceptInviteResponse, error) { token, err := s.repo.GetToken(ctx, req.InviteToken.Token) if err != nil { - if errors.Is(err, invite.ErrTokenNotFound) { + if errors.Is(err, ocmd.ErrTokenInvalid) { return &invitepb.AcceptInviteResponse{ - Status: status.NewNotFound(ctx, "token not found"), + Status: status.NewInvalid(ctx, "token invalid or not found"), }, nil } return &invitepb.AcceptInviteResponse{ @@ -250,7 +246,7 @@ func (s *service) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteRe if !isTokenValid(token) { return &invitepb.AcceptInviteResponse{ - Status: status.NewInvalid(ctx, "token is not valid"), + Status: status.NewInvalid(ctx, "token invalid or not found"), }, nil } diff --git a/internal/http/services/experimental/sciencemesh/token.go b/internal/http/services/experimental/sciencemesh/token.go index a1c783b816..a4708ac69c 100644 --- a/internal/http/services/experimental/sciencemesh/token.go +++ b/internal/http/services/experimental/sciencemesh/token.go @@ -177,17 +177,14 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) { } if forwardInviteResponse.Status.Code != rpc.Code_CODE_OK { switch forwardInviteResponse.Status.Code { - case rpc.Code_CODE_NOT_FOUND: - reqres.WriteError(w, r, reqres.APIErrorNotFound, "token not found", nil) - return case rpc.Code_CODE_INVALID_ARGUMENT: - reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, "token has expired", nil) + reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, "invalid or non existing token", nil) return case rpc.Code_CODE_ALREADY_EXISTS: - reqres.WriteError(w, r, reqres.APIErrorAlreadyExist, "user already known", nil) + reqres.WriteError(w, r, reqres.APIErrorAlreadyExist, "invitation already accepted", nil) return case rpc.Code_CODE_PERMISSION_DENIED: - reqres.WriteError(w, r, reqres.APIErrorUnauthenticated, "remove service not trusted", nil) + reqres.WriteError(w, r, reqres.APIErrorUnauthenticated, "remote service not trusted", nil) return default: reqres.WriteError(w, r, reqres.APIErrorServerError, "unexpected error: "+forwardInviteResponse.Status.Message, errors.New(forwardInviteResponse.Status.Message)) diff --git a/internal/http/services/opencloudmesh/ocmd/client.go b/internal/http/services/opencloudmesh/ocmd/client.go index 106f51e5ad..1738957333 100644 --- a/internal/http/services/opencloudmesh/ocmd/client.go +++ b/internal/http/services/opencloudmesh/ocmd/client.go @@ -35,20 +35,16 @@ import ( ) // ErrTokenInvalid is the error returned by the invite-accepted -// endpoint when the token is not valid. -var ErrTokenInvalid = errors.New("the invitation token is invalid") +// endpoint when the token is not valid or not existing. +var ErrTokenInvalid = errors.New("the invitation token is invalid or not found") // ErrServiceNotTrusted is the error returned by the invite-accepted // endpoint when the service is not trusted to accept invitations. var ErrServiceNotTrusted = errors.New("service is not trusted to accept invitations") // ErrUserAlreadyAccepted is the error returned by the invite-accepted -// endpoint when a user is already know by the remote cloud. -var ErrUserAlreadyAccepted = errors.New("user already accepted an invitation token") - -// ErrTokenNotFound is the error returned by the invite-accepted -// endpoint when the request is done using a not existing token. -var ErrTokenNotFound = errors.New("token not found") +// endpoint when a token was already used by a user in the remote cloud. +var ErrUserAlreadyAccepted = errors.New("invitation already accepted") // ErrInvalidParameters is the error returned by the shares endpoint // when the request does not contain required properties. @@ -250,8 +246,6 @@ func (c *OCMClient) parseInviteAcceptedResponse(r *http.Response) (*User, error) return &u, nil case http.StatusBadRequest: return nil, ErrTokenInvalid - case http.StatusNotFound: - return nil, ErrTokenNotFound case http.StatusConflict: return nil, ErrUserAlreadyAccepted case http.StatusForbidden: diff --git a/tests/integration/grpc/ocm_invitation_test.go b/tests/integration/grpc/ocm_invitation_test.go index c7268b44ae..1427963ba6 100644 --- a/tests/integration/grpc/ocm_invitation_test.go +++ b/tests/integration/grpc/ocm_invitation_test.go @@ -281,7 +281,7 @@ var _ = Describe("ocm invitation workflow", func() { OriginSystemProvider: cernbox, }) Expect(err).ToNot(HaveOccurred()) - Expect(forwardRes.Status.Code).To(Equal(rpc.Code_CODE_NOT_FOUND)) + Expect(forwardRes.Status.Code).To(Equal(rpc.Code_CODE_INVALID_ARGUMENT)) }) })