Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit 87e4d5b

Browse files
committed
Upgrade package version to v2.5.3
1 parent 16df519 commit 87e4d5b

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

lib/rate-limiter.interceptor.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class RateLimiterInterceptor implements NestInterceptor {
2929
this.spesificOptions = null
3030
this.spesificOptions = options
3131

32-
3332
const limiterOptions: RateLimiterOptions = {
3433
...this.options,
3534
...options
@@ -39,7 +38,8 @@ export class RateLimiterInterceptor implements NestInterceptor {
3938

4039
let rateLimiter: RateLimiterAbstract = this.rateLimiters.get(libraryArguments.keyPrefix)
4140

42-
if (libraryArguments.execEvenlyMinDelayMs === undefined) libraryArguments.execEvenlyMinDelayMs = (this.options.duration * 1000) / this.options.points
41+
if (libraryArguments.execEvenlyMinDelayMs === undefined)
42+
libraryArguments.execEvenlyMinDelayMs = (this.options.duration * 1000) / this.options.points
4343

4444
if (!rateLimiter) {
4545
switch (this.spesificOptions?.type || this.options.type) {
@@ -56,7 +56,7 @@ export class RateLimiterInterceptor implements NestInterceptor {
5656
Logger.log(`Rate Limiter started with ${limiterOptions.keyPrefix} key prefix`, 'RateLimiterMemcache')
5757
break
5858
case 'Postgres':
59-
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
59+
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
6060

6161
libraryArguments.tableName = this.spesificOptions?.tableName || this.options.tableName
6262
if (libraryArguments.tableName === undefined) {
@@ -78,7 +78,7 @@ export class RateLimiterInterceptor implements NestInterceptor {
7878
Logger.log(`Rate Limiter started with ${limiterOptions.keyPrefix} key prefix`, 'RateLimiterPostgres')
7979
break
8080
case 'MySQL':
81-
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
81+
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
8282

8383
libraryArguments.tableName = this.spesificOptions?.tableName || this.options.tableName
8484
if (libraryArguments.tableName === undefined) {
@@ -100,7 +100,7 @@ export class RateLimiterInterceptor implements NestInterceptor {
100100
Logger.log(`Rate Limiter started with ${limiterOptions.keyPrefix} key prefix`, 'RateLimiterMySQL')
101101
break
102102
case 'Mongo':
103-
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
103+
if (libraryArguments.storeType === undefined) libraryArguments.storeType = this.options.storeClient.constructor.name
104104

105105
libraryArguments.tableName = this.spesificOptions?.tableName || this.options.tableName
106106
if (libraryArguments.tableName === undefined) {
@@ -190,15 +190,18 @@ export class RateLimiterInterceptor implements NestInterceptor {
190190
response.header('X-Retry-Remaining', rateLimiterResponse.remainingPoints)
191191
response.header('X-Retry-Reset', new Date(Date.now() + rateLimiterResponse.msBeforeNext).toUTCString())
192192
}
193-
return next.handle()
194193
} catch (rateLimiterResponse) {
195194
response.header('Retry-After', Math.ceil(rateLimiterResponse.msBeforeNext / 1000))
196-
response.code(429).header('Content-Type', 'application/json; charset=utf-8').send({
197-
statusCode: HttpStatus.TOO_MANY_REQUESTS,
198-
error: 'Too Many Requests',
199-
message: this.spesificOptions?.errorMessage || this.options.errorMessage
200-
})
195+
response
196+
.code(429)
197+
.header('Content-Type', 'application/json; charset=utf-8')
198+
.send({
199+
statusCode: HttpStatus.TOO_MANY_REQUESTS,
200+
error: 'Too Many Requests',
201+
message: this.spesificOptions?.errorMessage || this.options.errorMessage
202+
})
201203
}
204+
return next.handle()
202205
} else {
203206
try {
204207
if (this.spesificOptions?.queueEnabled || this.options.queueEnabled) await this.queueLimiter.removeTokens(1)
@@ -210,7 +213,6 @@ export class RateLimiterInterceptor implements NestInterceptor {
210213
response.set('X-Retry-Remaining', rateLimiterResponse.remainingPoints)
211214
response.set('X-Retry-Reset', new Date(Date.now() + rateLimiterResponse.msBeforeNext).toUTCString())
212215
}
213-
return next.handle()
214216
} catch (rateLimiterResponse) {
215217
response.set('Retry-After', Math.ceil(rateLimiterResponse.msBeforeNext / 1000))
216218
response.status(429).json({
@@ -219,6 +221,7 @@ export class RateLimiterInterceptor implements NestInterceptor {
219221
message: this.spesificOptions?.errorMessage || this.options.errorMessage
220222
})
221223
}
224+
return next.handle()
222225
}
223226
}
224227
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs-rate-limiter",
3-
"version": "2.5.2",
3+
"version": "2.5.3",
44
"description": "Highly configurable rate limiter library",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)