From 95632f58800f19a3c8ee98ea3d2dd146b51e8d59 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 28 Jul 2020 11:17:28 +0200 Subject: [PATCH] Fix throttler not triggering when maxCount > 1 --- src/Throttler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Throttler.ts b/src/Throttler.ts index 2996ad0..5235ace 100644 --- a/src/Throttler.ts +++ b/src/Throttler.ts @@ -62,7 +62,7 @@ class Throttle { let timeDiff = currentDate - trigger.lastTrigger; if (timeDiff > this.holdPeriod) { timeDiff -= this.holdPeriod; - trigger.count = Math.floor(Math.min(trigger.count, this.max * (1 - timeDiff / this.resetPeriod))); + trigger.count = Math.floor(Math.min(trigger.count, (this.max + 1) * (1 - timeDiff / this.resetPeriod))); } } @@ -76,7 +76,7 @@ class Throttle { } } - private throw(unjailedIn: number) { + protected throw(unjailedIn: number) { throw new TooManyRequestsHttpError(unjailedIn); } } \ No newline at end of file