Skip to content

Commit

Permalink
Include 429, standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffmcfadden committed May 22, 2024
1 parent 36a498f commit d498839
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ghx (0.2.1)
ghx (0.3.0)
faraday (~> 2.9.0)
faraday-retry (~> 2.2.1)
octokit
Expand Down
4 changes: 3 additions & 1 deletion lib/ghx/errors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module GHX
class GHXError < StandardError; end

class RateLimitExceededError < GHXError; end

class OtherApiError < GHXError; end
end
end
3 changes: 1 addition & 2 deletions lib/ghx/rest_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _http_request(uri:, request:)

if response.code.to_i < 400
response
elsif response.code.to_i == 403
elsif [403, 429].include?(response.code.to_i)
if response["X-RateLimit-Remaining"].to_i == 0
reset_time = Time.at(response["X-RateLimit-Reset"].to_i)
raise GHX::RateLimitExceededError, "GitHub API rate limit exceeded. Try again after #{reset_time}"
Expand All @@ -82,6 +82,5 @@ def _http_request(uri:, request:)
raise GHX::OtherApiError, "GitHub API returned an error: #{response.code} #{response.body}"
end
end

end
end

0 comments on commit d498839

Please sign in to comment.