Fix rate limiting: handle Redis unavailability gracefully to prevent email failures

This commit is contained in:
TheMaddax 2025-09-11 10:48:42 -06:00
parent 788ce88288
commit 265b439449

View file

@ -39,6 +39,7 @@ export class RateLimit {
} }
async check(config: RateLimitConfig): Promise<RateLimitResult> { async check(config: RateLimitConfig): Promise<RateLimitResult> {
try {
const ip = await this.getIP() const ip = await this.getIP()
const key = this.getKey(ip) const key = this.getKey(ip)
const now = Math.floor(Date.now() / 1000) const now = Math.floor(Date.now() / 1000)
@ -58,6 +59,17 @@ export class RateLimit {
remaining, remaining,
reset: windowStart + config.interval reset: windowStart + config.interval
} }
} catch (error) {
console.warn('Redis unavailable, allowing request (rate limiting disabled):', error)
// Fallback: allow the request when Redis is unavailable
// TODO: Fix Redis connection or create new instance
return {
success: true,
limit: config.limit,
remaining: config.limit - 1,
reset: Math.floor(Date.now() / 1000) + config.interval
}
}
} }
} }