diff --git a/pkg/connector/group.go b/pkg/connector/group.go index cae39f88..b63cea47 100644 --- a/pkg/connector/group.go +++ b/pkg/connector/group.go @@ -175,27 +175,28 @@ func (o *groupResourceType) Grants( case resourceTypeRole.Id: roles, resp, err := listGroupAssignedRoles(ctx, o.connector.client, groupID, nil) if err != nil { - if resp != nil { - defer resp.Body.Close() - errOkta, err := getError(resp) + if resp == nil { + return nil, "", nil, fmt.Errorf("okta-connectorv2: failed to list group roles: %w", err) + } + + defer resp.Body.Close() + errOkta, err := getError(resp) + if err != nil { + return nil, "", nil, err + } + if errOkta.ErrorCode == AccessDeniedErrorCode { + err = bag.Next("") if err != nil { return nil, "", nil, err } - if errOkta.ErrorCode == AccessDeniedErrorCode { - err = bag.Next("") - if err != nil { - return nil, "", nil, err - } - pageToken, err := bag.Marshal() - if err != nil { - return nil, "", nil, err - } - return nil, pageToken, nil, nil - } else { - return nil, "", nil, fmt.Errorf("okta-connectorv2: failed to list group roles: %v", errOkta) + pageToken, err := bag.Marshal() + if err != nil { + return nil, "", nil, err } + return nil, pageToken, nil, nil + } else { + return nil, "", nil, fmt.Errorf("okta-connectorv2: failed to list group roles: %v", errOkta) } - return nil, "", nil, fmt.Errorf("okta-connectorv2: failed to list group roles: %w", err) } for _, role := range roles {