2
0
yuken 3 жил өмнө
parent
commit
487cad7a24

+ 7 - 7
packages/app/src/server/middlewares/api-rate-limiter.ts

@@ -29,13 +29,13 @@ const apiRateLimitConfig = generateApiRateLimitConfig();
 
 
 const consumePoints = async(rateLimiter: RateLimiterMongo, key: string, points: number, next: NextFunction) => {
 const consumePoints = async(rateLimiter: RateLimiterMongo, key: string, points: number, next: NextFunction) => {
   const consumePoints = defaultMaxPoints / points;
   const consumePoints = defaultMaxPoints / points;
-  await rateLimiter.consume(key, consumePoints)
-    .then(() => {
-      next();
-    })
-    .catch(() => {
-      logger.error(`too many request at ${key}`);
-    });
+  try {
+    await rateLimiter.consume(key, consumePoints);
+    next();
+  }
+  catch {
+    logger.error(`too many request at ${key}`);
+  }
 };
 };
 
 
 module.exports = () => {
 module.exports = () => {