Raise RateLimitError w/ retry_after on HTTP 429 - #29
Merged
Conversation
429 previously mapped to generic Error, indistinguishable from 400 - callers couldn't retry_on it or tell rate limiting apart from bad requests. New RateLimitError subclasses Error (existing rescues keep working), keeps the same message, and exposes retry_after (Retry-After header normalized to seconds; nil if absent). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PASS Tools' daily inventory email run bursts ~340 jobs at 9:00 UTC and trips MyTankInfo's rate limit (Sentry PASS-TOOLS-BQ).
handle_responsemapped 429 to the genericMyTankInfo::Error— the same class as 400 — so callers couldn't distinguish rate limiting from malformed requests, couldn'tretry_onit in ActiveJob, and the Credential auth fallback misread a 429 during token refresh as a rejected refresh token and fired a second auth call.What
MyTankInfo::RateLimitError < Errorraised on HTTP 429. Same message format as before, and it subclassesError, so existing rescues are unaffected.error.retry_afterexposes the response'sRetry-Afterheader normalized to seconds (handles both delay-seconds and HTTP-date forms);nilwhen the header is absent.JwtClient#authenticate!/refresh!propagate it (they go throughpost_request→handle_response); tests verify a 429 on refresh raisesRateLimitErrorand does not trigger the full re-auth fallback.Downstream (planned in pass-tools, not part of this PR)
EmailDeliveryJob:retry_on MyTankInfo::RateLimitErrorCredential#fresh_my_tank_info_access_token!: re-raiseRateLimitErrorinstead of falling back to full authTesting
rake test: 97 runs, 265 assertions, 0 failures.🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.