GeezerVison is showing github.com — feat(rateLimit): `dryRun`, `onLimited`, and no `rateLimitRes` on the error by fratzinger · Pull Request #84 · feathersjs/feathers-utils
Conversation
fratzinger
commented
Nov 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
A limit set too tight rejects real traffic. dryRun lets a limit run in production first and only report, before it rejects anything:
consume(key, points)
under the limit → headers, next()
over the limit
+ onLimited(info, context) // every call over the limit
+ dryRun → headers, no Retry-After, next()
else → headers + Retry-After, throw TooManyRequests
dryRun?: boolean | PredicateFn — default false. A predicate decides per call, e.g. to enforce for some callers first. The call still consumes its points, so the headers and context.params.rateLimit show where it stands.
onLimited?: (info, context) => Promisable<void> — every call over the limit, rejected or let through; the hook for a log line or a metric. It gets the same RateLimitInfo as the headers.
- A store that fails is no call over the limit: it still rejects,
dryRun or not, and doesn't reach onLimited.
- Breaking: the rejection no longer carries
data.rateLimitRes (the TODO(next major)). An error's data goes to the client, and on a shared bucket the limiter's points tell every caller how much everyone else calls. data is { retryAfter, headers? }; the limiter's answer — or a failing store's error — stays on context.params.rateLimit.
throw new TooManyRequests('Too many requests', {
- rateLimitRes: res,
retryAfter,
...(values ? { headers: values } : {}),
})
Evidence
dryRun: true, 1 point / 60 s
1st call → passes, onLimited not called
2nd call → next() runs, RateLimit headers without Retry-After, consumedPoints 2,
onLimited({ limit: 1, remaining: 0, reset: 60, window: 60, limited: true }, context)
dryRun: context => context.params.trial
over the limit with trial → passes; without → TooManyRequests
onLimited without dryRun → called once, then TooManyRequests
rejection → error.data equals { retryAfter, headers } exactly; consumedPoints on context.params.rateLimit
failing store with dryRun → TooManyRequests without data, the store's error on context.params.rateLimit,
onLimited not called
pnpm test: 158 files, 2009 passed, no lint errors, no type errors.
Merge Danger
Door: two-way
dryRun and onLimited are off by default. Dropping rateLimitRes is a breaking change for anyone reading error.data.rateLimitRes — a major, or a minor if that's judged rare enough.
Blast Radius: small
Clients lose the limiter's raw points in the error body; retryAfter and the headers stay. Server code reading error.data.rateLimitRes reads context.params.rateLimit instead.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- `dryRun` (default `false`, or a predicate per call) lets a call over the
limit through: it still consumes its points and gets the headers, but no
`Retry-After` and no `TooManyRequests` - to measure a limit before
enforcing it.
- `onLimited(info, context)` is called for every call over the limit,
rejected or let through, e.g. to log or count it. A failing store is no
call over the limit and still rejects.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying feathers-utils with Cloudflare Pages
View logs
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
An error's `data` goes to the client, and on a shared bucket the
limiter's points tell every caller how much everyone else calls. The
rejection carries `retryAfter` and `headers` only; the limiter's answer -
or a failing store's error - stays on `context.params.rateLimit`.
BREAKING CHANGE: `TooManyRequests.data.rateLimitRes` is gone; read
`context.params.rateLimit` on the server instead.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fratzinger
changed the title
feat(rateLimit): dryRun and onLimited
feat(rateLimit): dryRun, onLimited, and no rateLimitRes on the error
Nov 6, 2026
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|