Skip to content

Commit

Permalink
support 429
Browse files Browse the repository at this point in the history
  • Loading branch information
gofri committed Dec 23, 2023
1 parent ddb9784 commit 2f982d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions github_ratelimit/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ const (
// the message or documentation URL is modified in the future.
// https://docs.github.com/en/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits
func (s SecondaryRateLimitBody) IsSecondaryRateLimit() bool {
return strings.HasPrefix(s.Message, SecondaryRateLimitMessage) || strings.HasSuffix(s.DocumentURL, SecondaryRateLimitDocumentationPathSuffix)
return strings.HasPrefix(s.Message, SecondaryRateLimitMessage) ||
strings.HasSuffix(s.DocumentURL, SecondaryRateLimitDocumentationPathSuffix)
}

// isRateLimitStatus checks whether the status code is a rate limit status code.
// see https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api#exceeding-the-rate-limit
func isRateLimitStatus(statusCode int) bool {
return statusCode == http.StatusForbidden || statusCode == http.StatusTooManyRequests
}

// isSecondaryRateLimit checks whether the response is a legitimate secondary rate limit.
// it is used to avoid handling primary rate limits and authentic HTTP Forbidden (403) responses.
func isSecondaryRateLimit(resp *http.Response) bool {
if resp.StatusCode != http.StatusForbidden {
if !isRateLimitStatus(resp.StatusCode) {
return false
}

Expand Down

0 comments on commit 2f982d1

Please sign in to comment.