Feat: Provide more details for 429 error msg
- Added better error code for when rate limit exceeded including consumed/remaining points, reset date and retry-after seconds
This commit is contained in:
parent
e5c8719554
commit
115204e6b6
@ -126,9 +126,11 @@ export async function supaAuthenticateUser(
|
||||
await rateLimiter.consume(iptoken);
|
||||
} catch (rateLimiterRes) {
|
||||
console.error(rateLimiterRes);
|
||||
const secs = Math.round(rateLimiterRes.msBeforeNext / 1000) || 1;
|
||||
const retryDate = new Date(Date.now() + rateLimiterRes.msBeforeNext);
|
||||
return {
|
||||
success: false,
|
||||
error: "Rate limit exceeded. Too many requests, try again in 1 minute.",
|
||||
error: `Rate limit exceeded for mode ${rateLimiter.keyPrefix}. Consumed points: ${rateLimiterRes.consumedPoints}, Remaining points: ${rateLimiterRes.remainingPoints}. Please retry after ${secs}s, resets at ${retryDate}`,
|
||||
status: 429,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user