Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map GRPC error codes to REVA errors #2140

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/map-grpc-error-codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Map GRPC error codes to REVA errors

We've fixed the error return behaviour in the gateway which would return GRPC error codes from the auth middleware. Now it returns REVA errors which other parts of REVA are also able to understand.

https://github.com/cs3org/reva/pull/2140
24 changes: 24 additions & 0 deletions pkg/rgrpc/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// NewOK returns a Status with CODE_OK.
Expand Down Expand Up @@ -169,6 +171,28 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
case errtypes.BadRequest:
return NewInvalidArg(ctx, "gateway: "+msg+":"+err.Error())
}

// map GRPC status codes coming from the auth middleware
grpcErr := err
for {
st, ok := status.FromError(grpcErr)
if ok {
switch st.Code() {
case codes.NotFound:
return NewNotFound(ctx, "gateway: "+msg+": "+err.Error())
case codes.Unauthenticated:
return NewUnauthenticated(ctx, err, "gateway: "+msg+": "+err.Error())
case codes.PermissionDenied:
return NewPermissionDenied(ctx, err, "gateway: "+msg+": "+err.Error())
}
}
// the actual error can be wrapped multiple times
grpcErr = errors.Unwrap(grpcErr)
if grpcErr == nil {
break
}
}

return NewInternal(ctx, err, "gateway: "+msg+":"+err.Error())
}

Expand Down