Skip to content

Commit f384bde

Browse files
authored
Merge pull request #102 from ConductorOne/lauren/wrap-unauthorized-err
wrap unauthorized err with status code
2 parents 7a0f93e + f5b2141 commit f384bde

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/connector/connector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ func getOrgs(ctx context.Context, client *github.Client, orgs []string) ([]strin
453453
if isRatelimited(resp) {
454454
return nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err)
455455
}
456+
if isAuthError(resp) {
457+
return nil, uhttp.WrapErrors(codes.Unauthenticated, "github-connector: failed to retrieve org", err)
458+
}
459+
if isPermissionError(resp) {
460+
return nil, uhttp.WrapErrors(codes.PermissionDenied, "github-connector: failed to retrieve org", err)
461+
}
456462
return nil, fmt.Errorf("github-connector: failed to retrieve org: %w", err)
457463
}
458464
if resp.StatusCode == http.StatusUnauthorized {

pkg/connector/helpers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,17 @@ func isRatelimited(resp *github.Response) bool {
235235
}
236236
return resp.StatusCode == http.StatusTooManyRequests
237237
}
238+
239+
func isAuthError(resp *github.Response) bool {
240+
if resp == nil {
241+
return false
242+
}
243+
return resp.StatusCode == http.StatusUnauthorized
244+
}
245+
246+
func isPermissionError(resp *github.Response) bool {
247+
if resp == nil {
248+
return false
249+
}
250+
return resp.StatusCode == http.StatusForbidden
251+
}

0 commit comments

Comments
 (0)