Skip to content

Commit 3cd02a5

Browse files
committed
cr
1 parent 72e287c commit 3cd02a5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1919
"go.uber.org/zap"
2020
"google.golang.org/grpc/codes"
21+
"google.golang.org/grpc/status"
2122
"google.golang.org/protobuf/proto"
2223
)
2324

@@ -204,7 +205,11 @@ func (o *orgResourceType) Grants(
204205
if isNotFoundError(resp) {
205206
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("org: %s not found", orgName))
206207
}
207-
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to list org members: %w", err)
208+
errMsg := "github-connectorv2: failed to list org members"
209+
if isRatelimited(resp) {
210+
return nil, "", nil, fmt.Errorf("%s: %w", errMsg, status.Error(codes.Unavailable, "too many requests"))
211+
}
212+
return nil, "", nil, fmt.Errorf("%s: %w", errMsg, err)
208213
}
209214

210215
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)