0

Merge pull request #190 from simonha9/simonha9/improve-rate-limit-error-msg

Feat: Provide more details for 429 error msg
This commit is contained in:
Nicolas 2024-05-26 18:07:42 -07:00 committed by GitHub
commit 67a53a9ae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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. Consumed points: ${rateLimiterRes.consumedPoints}, Remaining points: ${rateLimiterRes.remainingPoints}. Please retry after ${secs}s, resets at ${retryDate}`,
status: 429,
};
}