mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: Distinguish rate limiter error (#12479)
This commit is contained in:
@@ -69,23 +69,24 @@ export function defaultRateLimiter() {
|
||||
try {
|
||||
await limiter.consume(key);
|
||||
} catch (rateLimiterRes) {
|
||||
if (rateLimiterRes.msBeforeNext) {
|
||||
ctx.set("Retry-After", `${rateLimiterRes.msBeforeNext / 1000}`);
|
||||
ctx.set("RateLimit-Limit", `${limiter.points}`);
|
||||
ctx.set("RateLimit-Remaining", `${rateLimiterRes.remainingPoints}`);
|
||||
ctx.set(
|
||||
"RateLimit-Reset",
|
||||
new Date(Date.now() + rateLimiterRes.msBeforeNext).toString()
|
||||
);
|
||||
|
||||
Metrics.increment("rate_limit.exceeded", {
|
||||
path: fullPath,
|
||||
});
|
||||
|
||||
throw RateLimitExceededError();
|
||||
} else {
|
||||
if (rateLimiterRes instanceof Error) {
|
||||
Logger.error("Rate limiter error", rateLimiterRes);
|
||||
return next();
|
||||
}
|
||||
|
||||
ctx.set("Retry-After", `${rateLimiterRes.msBeforeNext / 1000}`);
|
||||
ctx.set("RateLimit-Limit", `${limiter.points}`);
|
||||
ctx.set("RateLimit-Remaining", `${rateLimiterRes.remainingPoints}`);
|
||||
ctx.set(
|
||||
"RateLimit-Reset",
|
||||
new Date(Date.now() + rateLimiterRes.msBeforeNext).toString()
|
||||
);
|
||||
|
||||
Metrics.increment("rate_limit.exceeded", {
|
||||
path: fullPath,
|
||||
});
|
||||
|
||||
throw RateLimitExceededError();
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user