Fix throttler not triggering when maxCount > 1

This commit is contained in:
Alice Gaudon 2020-07-28 11:17:28 +02:00
parent 97b2d3b94c
commit 95632f5880

View File

@ -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);
}
}