Skip to content

Commit 5658016

Browse files
committed
[BB-1151] baton-github: handle NotFound error in Grants
1 parent 15c3893 commit 5658016

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/connector/org.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import (
1313
"github.com/conductorone/baton-sdk/pkg/types/entitlement"
1414
"github.com/conductorone/baton-sdk/pkg/types/grant"
1515
"github.com/conductorone/baton-sdk/pkg/types/resource"
16+
"github.com/conductorone/baton-sdk/pkg/uhttp"
1617
"github.com/google/go-github/v69/github"
1718
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1819
"go.uber.org/zap"
20+
"google.golang.org/grpc/codes"
1921
"google.golang.org/protobuf/proto"
2022
)
2123

@@ -199,6 +201,9 @@ func (o *orgResourceType) Grants(
199201

200202
users, resp, err := o.client.Organizations.ListMembers(ctx, orgName, &opts)
201203
if err != nil {
204+
if isNotFoundError(resp) {
205+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("org: %s not found", orgName))
206+
}
202207
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to list org members: %w", err)
203208
}
204209

pkg/connector/repository.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import (
1313
"github.com/conductorone/baton-sdk/pkg/types/entitlement"
1414
"github.com/conductorone/baton-sdk/pkg/types/grant"
1515
"github.com/conductorone/baton-sdk/pkg/types/resource"
16+
"github.com/conductorone/baton-sdk/pkg/uhttp"
1617
"github.com/google/go-github/v69/github"
1718
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1819
"go.uber.org/zap"
20+
"google.golang.org/grpc/codes"
1921
)
2022

2123
// outside collaborators are given one of these roles too.
@@ -176,6 +178,9 @@ func (o *repositoryResourceType) Grants(
176178
}
177179
return nil, pageToken, nil, nil
178180
}
181+
if isNotFoundError(resp) {
182+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("repo: %s not found", resource.DisplayName))
183+
}
179184
return nil, "", nil, fmt.Errorf("github-connector: failed to list repos: %w", err)
180185
}
181186

@@ -224,6 +229,10 @@ func (o *repositoryResourceType) Grants(
224229
}
225230
return nil, pageToken, nil, nil
226231
}
232+
233+
if isNotFoundError(resp) {
234+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("repo: %s not found", resource.DisplayName))
235+
}
227236
return nil, "", nil, fmt.Errorf("github-connector: failed to list repos: %w", err)
228237
}
229238

0 commit comments

Comments
 (0)