Skip to content

Commit 7a01321

Browse files
committed
cr
1 parent ccccc25 commit 7a01321

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pkg/connector/helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,10 @@ func isNotFoundError(resp *github.Response) bool {
225225
}
226226
return resp.StatusCode == http.StatusNotFound
227227
}
228+
229+
func isRatelimited(resp *github.Response) bool {
230+
if resp == nil {
231+
return false
232+
}
233+
return resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusTooManyRequests
234+
}

pkg/connector/org.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/google/go-github/v69/github"
1717
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1818
"go.uber.org/zap"
19+
"google.golang.org/grpc/codes"
20+
"google.golang.org/grpc/status"
1921
"google.golang.org/protobuf/proto"
2022
)
2123

@@ -199,7 +201,11 @@ func (o *orgResourceType) Grants(
199201

200202
users, resp, err := o.client.Organizations.ListMembers(ctx, orgName, &opts)
201203
if err != nil {
202-
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to list org members: %w", err)
204+
errMsg := "github-connectorv2: failed to list org members"
205+
if isRatelimited(resp) {
206+
return nil, "", nil, fmt.Errorf("%s: %w", errMsg, status.Error(codes.Unavailable, "too many requests"))
207+
}
208+
return nil, "", nil, fmt.Errorf("%s: %w", errMsg, err)
203209
}
204210

205211
nextPage, reqAnnos, err := parseResp(resp)

pkg/connector/team.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
186186
if isNotFoundError(resp) {
187187
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("org: %d not found", org.GetID()))
188188
}
189+
if isRatelimited(resp) {
190+
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests")
191+
}
189192
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to fetch team members: %w", err)
190193
}
191194

0 commit comments

Comments
 (0)