Skip to content

Commit

Permalink
fix: handle failedprecondition error (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina authored Sep 19, 2024
1 parent beee146 commit dd036a8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions core/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/goto/shield/internal/schema"
"github.com/goto/shield/pkg/db"
"github.com/goto/shield/pkg/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
Expand Down Expand Up @@ -409,7 +411,13 @@ func (s Service) ListUserResourcesByType(ctx context.Context, userID string, res

res, err := s.listUserResources(ctx, resourceType, user)
if err != nil {
return ResourcePermissions{}, err
switch status.Code(err) {
case codes.FailedPrecondition:
s.logger.Warn(err.Error())
return ResourcePermissions{}, ErrInvalidDetail
default:
return ResourcePermissions{}, err
}
}

return res, nil
Expand Down Expand Up @@ -440,7 +448,13 @@ func (s Service) ListAllUserResources(ctx context.Context, userID string, resour
if _, ok := result[res]; !ok {
list, err := s.listUserResources(ctx, res, user)
if err != nil {
return map[string]ResourcePermissions{}, err
switch status.Code(err) {
case codes.FailedPrecondition:
s.logger.Warn(err.Error())
continue
default:
return map[string]ResourcePermissions{}, err
}
}
if len(list) != 0 {
result[res] = list
Expand All @@ -467,6 +481,12 @@ func (s Service) listUserResources(ctx context.Context, resourceType string, use
actMap[action] = true
resources, err := s.relationService.LookupResources(ctx, resourceType, action, userNamespace, user.ID)
if err != nil {
// continue if permission under a namespace is not found
// https://github.com/authzed/spicedb/blob/main/internal/dispatch/graph/errors.go#L73
if strings.Contains(err.Error(), "not found under definition") {
s.logger.Warn(err.Error())
continue
}
return ResourcePermissions{}, err
}

Expand Down

0 comments on commit dd036a8

Please sign in to comment.