docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

docs(throttler): update WebSockets example for multiple throttle limits

Open Antraxmin opened this issue 6 months ago • 0 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/docs.nestjs.com/blob/master/CONTRIBUTING.md

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [x] Docs
  • [ ] Other... Please describe:

What is the current behavior?

Currently, the documentation for WebSockets and rate limiting provides an example of using the throttler guard with WebSockets. However, it does not take into account multiple throttle limit configurations and does not explain that the handleRequest method will be called multiple times when multiple throttler limits are set.

So, This PR updates the Throttler documentation for WebSockets to fix issue #3041. The current WebSockets example doesn't properly explain how multiple throttle limit configurations are handled, which can lead to incorrect implementations.

What is the new behavior?

  • Added a clear note explaining that handleRequest is called for each throttle configuration when multiple limits are defined
  • Created a comprehensive example showing how to properly handle multiple throttle configurations in WebSockets
  • Added module configuration example to show the complete picture
  • Added explicit return type for async methods
  • Provided comments explaining how throttler.name can be used to identify different configurations
  • Made the examples consistent with NestJS documentation style

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

The documentation now clearly explains how multiple throttle limits work with WebSockets and provides a comprehensive example. Users will understand that they need to handle multiple throttle limits if they are configured, rather than just a single limit.

Antraxmin avatar Apr 06 '25 07:04 Antraxmin