Skip to content

Commit c87b79a

Browse files
committed
add rate limit data to errors for retries
1 parent b8e183c commit c87b79a

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

pkg/connector/api_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (o *apiTokenResourceType) List(
9595
})
9696
if err != nil {
9797
if isRatelimited(resp) {
98-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
98+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
9999
}
100100
return nil, "", nil, err
101101
}

pkg/connector/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func getOrgs(ctx context.Context, client *github.Client, orgs []string) ([]strin
459459
orgs, resp, err := client.Organizations.List(ctx, "", &github.ListOptions{Page: page, PerPage: maxPageSize})
460460
if err != nil {
461461
if isRatelimited(resp) {
462-
return nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
462+
return nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
463463
}
464464
if isAuthError(resp) {
465465
return nil, uhttp.WrapErrors(codes.Unauthenticated, "github-connector: failed to retrieve org", err)

pkg/connector/enterprise_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (o *enterpriseRoleResourceType) Grants(
143143
user, resp, err := o.userCache.GetUserByLogin(ctx, userLogin)
144144
if err != nil {
145145
if isRatelimited(resp) {
146-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
146+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
147147
}
148148
return nil, "", nil, fmt.Errorf("baton-github: error getting user %s: %w", userLogin, err)
149149
}

pkg/connector/org.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (o *orgResourceType) List(
104104
orgs, resp, err := o.client.Organizations.List(ctx, "", opts)
105105
if err != nil {
106106
if isRatelimited(resp) {
107-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
107+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
108108
}
109109
return nil, "", nil, fmt.Errorf("github-connector: failed to fetch org: %w", err)
110110
}
@@ -132,7 +132,7 @@ func (o *orgResourceType) List(
132132
}
133133

134134
if isRatelimited(resp) {
135-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
135+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
136136
}
137137
return nil, "", nil, err
138138
}
@@ -230,7 +230,7 @@ func (o *orgResourceType) Grants(
230230
}
231231
errMsg := "github-connectorv2: failed to list org members"
232232
if isRatelimited(resp) {
233-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
233+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
234234
}
235235
return nil, "", nil, fmt.Errorf("%s: %w", errMsg, err)
236236
}

pkg/connector/org_role.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (o *orgRoleResourceType) List(
9292
return nil, "", nil, nil
9393
}
9494
if isRatelimited(resp) {
95-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
95+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
9696
}
9797
return nil, "", nil, fmt.Errorf("failed to list organization roles: %w", err)
9898
}
@@ -229,7 +229,7 @@ func (o *orgRoleResourceType) Grants(
229229
return nil, pageToken, nil, nil
230230
}
231231
if isRatelimited(resp) {
232-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
232+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
233233
}
234234
return nil, "", nil, fmt.Errorf("failed to list role teams: %w", err)
235235
}

pkg/connector/repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (o *repositoryResourceType) Grants(
184184
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("repo: %s not found", resource.DisplayName))
185185
}
186186
if isRatelimited(resp) {
187-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
187+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
188188
}
189189
return nil, "", nil, fmt.Errorf("github-connector: failed to list repos: %w", err)
190190
}
@@ -240,7 +240,7 @@ func (o *repositoryResourceType) Grants(
240240
}
241241

242242
if isRatelimited(resp) {
243-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
243+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
244244
}
245245
return nil, "", nil, fmt.Errorf("github-connector: failed to list repos: %w", err)
246246
}

pkg/connector/team.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (o *teamResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
9898
teams, resp, err := o.client.Teams.ListTeams(ctx, orgName, opts)
9999
if err != nil {
100100
if isRatelimited(resp) {
101-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
101+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
102102
}
103103
return nil, "", nil, fmt.Errorf("github-connector: failed to list teams: %w", err)
104104
}
@@ -112,7 +112,7 @@ func (o *teamResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
112112
fullTeam, resp, err := o.teamCache.GetTeam(ctx, orgID, team.GetID())
113113
if err != nil {
114114
if isRatelimited(resp) {
115-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
115+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
116116
}
117117
return nil, "", nil, err
118118
}
@@ -175,7 +175,7 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
175175
org, resp, err := o.client.Organizations.GetByID(ctx, orgID)
176176
if err != nil {
177177
if isRatelimited(resp) {
178-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
178+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
179179
}
180180
return nil, "", nil, err
181181
}
@@ -214,7 +214,7 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
214214
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("org: %d not found", org.GetID()))
215215
}
216216
if isRatelimited(resp) {
217-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
217+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
218218
}
219219
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to fetch team members: %w", err)
220220
}

pkg/connector/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (o *userResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
135135
users, resp, err := o.client.Organizations.ListMembers(ctx, orgName, &opts)
136136
if err != nil {
137137
if isRatelimited(resp) {
138-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
138+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, resp.Response, err)
139139
}
140140
return nil, "", nil, fmt.Errorf("github-connector: ListMembers failed: %w", err)
141141
}
@@ -161,7 +161,7 @@ func (o *userResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
161161
u, res, err := o.userCache.GetUser(ctx, user.GetID())
162162
if err != nil {
163163
if isRatelimited(res) {
164-
return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
164+
return nil, "", nil, uhttp.WrapErrorsWithRateLimitInfo(codes.Unavailable, res.Response, err)
165165
}
166166
// This undocumented API can return 404 for some users. If this fails it means we won't get some of their details like email
167167
if res == nil || res.StatusCode != http.StatusNotFound {

0 commit comments

Comments
 (0)