Conversation
The Discogs API returns `X-Discogs-Ratelimit`, `-Used` and `-Remaining` on every response, but a consumer had no way to read them: `maybeUpdateLimiter` consumed two of the three to retune the internal limiter and dropped them, and `-Used` was never read at all. An app that wants to show a user their remaining budget, or pace itself off it rather than guessing, had nothing to work with. Adds `onRateLimit`, called with a `RateLimitInfo` for every response. It fires before the status checks, so it reports on error responses too -- a 429 is precisely when those numbers matter most. A throwing callback is swallowed; a consumer's reporting hook should not be able to fail their request. Absent or malformed headers now yield undefined rather than NaN, which also tidies the existing limiter logic. `DiscogsError` gains `retryAfter`, parsed from `Retry-After`, so a 429 can be waited out for the right length of time instead of a guessed one. The constructor argument is optional, so no existing call site changes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
The Discogs API returns rate limit info on every response, but a consumer has no way to read them. (The values are consumed internally by
maybeUpdateLimiter.) This change allows an app to show a user their remaining budget or pace its requests intentionally based on the real budget numbers.Adds an optional
onRateLimitcallback invoked for each response. It fires before the status check so it can report on errors, since a 429 is exactly when it's most interesting. It swallows callback exceptions so it won't fail requests. (Absent or malformed headers areundefinedrather thanNaN, which cleans up some existing limiter logic.)Adds
DiscogsError.retryAfter?, parsed fromRetry-After. This lets a client wait out a 429 for the right length of time instead of a guessing. The constructor argument is optional, so no existing call site changes.I chose a callback to avoid adding fields to every method's return type.