Skip to content

Commit

Permalink
map GRPC error codes to REVA errors (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek authored Oct 7, 2021
1 parent 7b7dbb0 commit c0cae2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit c0cae2a

Please sign in to comment.