fix: use 'success' value for better accuracy (#14624)
* fix: use 'success' value for better accuracy * add success to test --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
2 files changed
+4
-2
No files matched your search
@@ -10,11 +10,11 @@ export async function checkRateLimitAndThrowError({
|
||||
opts,
|
||||
}: RateLimitHelper) {
|
||||
const response = await rateLimiter()({ rateLimitingType, identifier, opts });
|
||||
const { remaining, reset } = response;
|
||||
const { success, reset } = response;
|
||||
|
||||
if (onRateLimiterResponse) onRateLimiterResponse(response);
|
||||
|
||||
if (remaining < 1) {
|
||||
if (!success) {
|
||||
const convertToSeconds = (ms: number) => Math.floor(ms / 1000);
|
||||
const secondsToWait = convertToSeconds(reset - Date.now());
|
||||
throw new TRPCError({
|
||||
|
||||
Reference in new issue
Block a user