Repository navigation
feat: emit limit:exceeded event when a request is rejected - #21
Merged
Merged
Conversation
The event is emitted every time a request is rejected because the key has exhausted its requests, across consume, attempt, penalize, multi limiters and HTTP throttling. Methods that only update the counters, like increment or set, do not emit the event. The provider passes the app emitter to the limiter manager, which shares it with the limiters it creates. The emitter is optional for standalone usage.
…event # Conflicts: # src/limiter.ts
2 of 3 tasks
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.
📚 Description
Adds a
limit:exceededevent, emitted every time a request is rejected because the key has exhausted its requests.The event is emitted from every rejection path, exactly once per rejection:
Limiter.consume()when the store rejects the request (coversattempt()andMultiLimiter.consume()too)attempt(),penalize(),MultiLimiter.penalize()andHttpLimiter.throttle()Methods that only update the counters (
increment(),set(),block()) do not emit the event. The next rejected request does.The payload is
{ key, response }. For limiters created usinglimiter.define(), the key is prefixed with the limiter name (e.g.login_ip_127.0.0.1), which can be used to identify the limiter.Wiring
LimiterManager, which shares it with everyLimiterandMultiLimiterit creates.EventsListfor typed listeners.Context
Comes out of the discussion on #19. A global event serves observability for enforced limits as well, and lets the dry run mode proposed in #20 report through the same event instead of the
limitExceededcallback.🤖 Generated with Claude Code