Fix rate limiting: handle Redis unavailability gracefully to prevent email failures
This commit is contained in:
parent
788ce88288
commit
265b439449
1 changed files with 28 additions and 16 deletions
|
|
@ -39,6 +39,7 @@ export class RateLimit {
|
|||
}
|
||||
|
||||
async check(config: RateLimitConfig): Promise<RateLimitResult> {
|
||||
try {
|
||||
const ip = await this.getIP()
|
||||
const key = this.getKey(ip)
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
|
|
@ -58,6 +59,17 @@ export class RateLimit {
|
|||
remaining,
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue