@cortec/polka
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -155,6 +155,9 @@ "use strict"; | ||
if (rateLimit && controller.rateLimit) { | ||
const rateLimitRes = await rateLimit.consume(controller.rateLimit.count.call(ctx, req, reqCtx)); | ||
if (!rateLimitRes) { | ||
throw new ResponseError_1.default(HttpStatusCodes_1.default.TOO_MANY_REQUESTS, 'Too many requests', {}); | ||
} | ||
await rateLimit | ||
.consume(controller.rateLimit.count.call(ctx, req, reqCtx)) | ||
.catch((err) => { | ||
throw new ResponseError_1.default(HttpStatusCodes_1.default.TOO_MANY_REQUESTS, 'Too many requests', { | ||
retryAfter: err.msBeforeNext / 1000 + 's', | ||
}); | ||
}); | ||
} | ||
@@ -161,0 +164,0 @@ if (controller.schema) { |
@@ -8,4 +8,4 @@ /// <reference types="node" /> | ||
constructor(statusCode: HttpStatusCode, message: string, details: T); | ||
get name(): "Forbidden" | "BadRequest" | "NotFound" | "ServerError" | "ClientError" | "Error"; | ||
get name(): "Forbidden" | "BadRequest" | "NotFound" | "RateLimit" | "ServerError" | "ClientError" | "Error"; | ||
send(res: http.ServerResponse): any; | ||
} |
@@ -22,2 +22,4 @@ "use strict"; | ||
return 'NotFound'; | ||
case HttpStatusCodes_1.default.TOO_MANY_REQUESTS: | ||
return 'RateLimit'; | ||
} | ||
@@ -24,0 +26,0 @@ if (this.statusCode >= 500) { |
{ | ||
"name": "@cortec/polka", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "<description>", | ||
@@ -48,3 +48,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "4216f2327771933ed5271a0304fb888293bee225" | ||
"gitHead": "d834fa3c493119b1a0c6f175d5322c54ff370a99" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51397
987