fix: Any error from rate limiter results in 'Rate limit exceeded' screen
This commit is contained in:
@@ -2,6 +2,7 @@ import { Context, Next } from "koa";
|
||||
import { defaults } from "lodash";
|
||||
import env from "@server/env";
|
||||
import { RateLimitExceededError } from "@server/errors";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import Metrics from "@server/logging/Metrics";
|
||||
import Redis from "@server/redis";
|
||||
import RateLimiter from "@server/utils/RateLimiter";
|
||||
@@ -27,6 +28,7 @@ export function defaultRateLimiter() {
|
||||
try {
|
||||
await limiter.consume(key);
|
||||
} catch (rateLimiterRes) {
|
||||
if (rateLimiterRes.points) {
|
||||
ctx.set("Retry-After", `${rateLimiterRes.msBeforeNext / 1000}`);
|
||||
ctx.set("RateLimit-Limit", `${limiter.points}`);
|
||||
ctx.set("RateLimit-Remaining", `${rateLimiterRes.remainingPoints}`);
|
||||
@@ -40,6 +42,9 @@ export function defaultRateLimiter() {
|
||||
});
|
||||
|
||||
throw RateLimitExceededError();
|
||||
} else {
|
||||
Logger.error("Rate limiter error", rateLimiterRes);
|
||||
}
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user