Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check rate limits for each request to GitHub #208

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

sleberknight
Copy link
Member

  • Modify GitHubApi to throw an IllegalStateException if the rate limit is exceeded (X-RateLimit-Remaining is 0). I chose to fail-fast here instead of assuming callers will always check the result. This is fine in this small application.
  • Move the rate limit check logic out of the GitHubResponse "from" factory method and into its own method, sendRequestAndCheckRateLimit. This keeps the "from" method simple and free of cross-cutting concerns.
  • Add several methods to GitHubResponse to get the reset time, the time until reset from a given date, and methods to check if the rate limit is exceeded.
  • Add rateLimitResource to GitHubResponse, so that it can be included in log and exception messages, which will be most useful if the rate limit is exceeded.
  • Add GitHubResponseTest as dedicated test of GitHubResponse

Misc:

  • Remove unused (except in tests) takeRequestWith1MilliTimeout from MockWebServerExtensions.kt
  • Add firstValueOrThrow to HttpHeadersExtensions.kt
  • Add top-level and extension functions in DateTimeExtensions.kt

Closes #173

* Modify GitHubApi to throw an IllegalStateException if
  the rate limit is exceeded (X-RateLimit-Remaining is 0).
  I chose to fail-fast here instead of assuming callers
  will always check the result. This is fine in this
  small application.
* Move the rate limit check logic out of the GitHubResponse
  "from" factory method and into its own method,
  sendRequestAndCheckRateLimit. This keeps the "from" method
  simple and free of cross-cutting concerns.
* Add several methods to GitHubResponse to get the
  reset time, the time until reset from a given date,
  and methods to check if the rate limit is exceeded.
* Add rateLimitResource to GitHubResponse, so that it
  can be included in log and exception messages, which
  will be most useful if the rate limit is exceeded.
* Add GitHubResponseTest as dedicated test of GitHubResponse

Misc:

* Remove unused (except in tests) takeRequestWith1MilliTimeout
  from MockWebServerExtensions.kt
* Add firstValueOrThrow to HttpHeadersExtensions.kt
* Add top-level and extension functions in DateTimeExtensions.kt

Closes #173
@sleberknight sleberknight self-assigned this Jul 22, 2024
Copy link

@sleberknight sleberknight merged commit f78baab into main Jul 22, 2024
5 checks passed
@sleberknight sleberknight deleted the 173-check-rate-limits branch July 22, 2024 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check rate limits when making HTTP calls to GitHub
1 participant