-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nan if register module with default and use Throttle decorator #1089
Comments
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project). |
sure issue reproduce on default route http://localhost:3000/ If use throttler module without redis error not throwing, but in memory storage saving Nan date |
Either that or set defaults that we know will be there. Defaults will be more sensible at the moment as to not need a breaking change. 20 hits per minute is the default of the
for the redis plugin, please bring that issue up with the package owner. This package is for the main logic and memory storage integration |
Defaults is good but someone may use logic where he set only limit param and if we set defaults its will be breaking change for him.
Depending on the solution in this package, I will either create a pull request on the redis package or we will solve the problem here :) |
I'd like to not have to worry about the |
Why not having early return as we had previously ?? (see 2c4b2ff), we just need to put it right after the limit and ttl resolution regarding context : // Check if specific limits are set at class or route level, otherwise use global options.
const limit = routeOrClassLimit || this.options.limit;
const ttl = routeOrClassTtl || this.options.ttl;
if (typeof limit === 'undefined' || typeof ttl === 'undefined') {
return true;
}
return this.handleRequest(context, limit, ttl); wdyt ? |
I'll need to find when we removed that and why, but it seems reasonable |
I am also having this issue, setting a default ttl and limit solves the problem. I am adding this so people like don't waste a lot of time finding out why this error shows up:
|
Will be fixed in 5.0.0 with #1565 |
In my case, nest says that "ttl" does not exists anymore. |
Is there an existing issue for this?
Current behavior
When
ThrottlerModule.forRoot()
is registered with no parameters and@Throttle
decorator is set on one of the methods and try to call method where decorator is not set we get Nan in ttlMilliseconds when in storageService trying to add keyconst ttlMilliseconds = ttl * 1000;
In memory realisation is we have
[Nan]
In https://github.com/kkoomen/nestjs-throttler-storage-redis realisation we have exception
Minimum reproduction code
later
Steps to reproduce
No response
Expected behavior
Ttl must not be Nan, maybe return earlier when ttl is not set or add default value. And need to fix typing from
handleRequest( context: ExecutionContext, limit: number, ttl: number, )
to
handleRequest( context: ExecutionContext, limit?: number, ttl?: number, )
Package version
8.1.3
NestJS version
8.1.3
Node.js version
16.13.1
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: