Issue Summary
The checkRateLimitAndThrowError function can generate a negative wait time in its error message when the reset timestamp is in the past. This results in incorrect and confusing user-facing messages.
Steps to Reproduce
- Call
checkRateLimitAndThrowError with a mocked rate limiter response where:
success = false
reset < Date.now()
- Observe the generated error message.
Example scenario:
reset = Date.now() - 5000;
Actual Results
The error message may display a negative wait time: Rate limit exceeded. Try again in -5 seconds.
Expected Results
The wait time should never be negative. It should be clamped to 0 or a minimum valid value: Rate limit exceeded. Try again in 0 seconds.
Technical details
- Node.js version: N/A (logic-level issue)
- Environment: Any
- This issue is reproducible via code without requiring UI interaction
Relevant code:
const secondsToWait = Math.floor((reset - Date.now()) / 1000);
Evidence
This is a deterministic logic issue:
If:
Then:
This leads to invalid negative values in the error message.
Suggested fix
Clamp the computed value to a minimum of 0:
const secondsToWait = Math.max(0, Math.floor((reset - Date.now()) / 1000));
Issue Summary
The
checkRateLimitAndThrowErrorfunction can generate a negative wait time in its error message when theresettimestamp is in the past. This results in incorrect and confusing user-facing messages.Steps to Reproduce
checkRateLimitAndThrowErrorwith a mocked rate limiter response where:success = falsereset < Date.now()Example scenario:
Actual Results
The error message may display a negative wait time:
Rate limit exceeded. Try again in -5 seconds.Expected Results
The wait time should never be negative. It should be clamped to 0 or a minimum valid value:
Rate limit exceeded. Try again in 0 seconds.Technical details
Relevant code:
Evidence
This is a deterministic logic issue:
If:
Then:
This leads to invalid negative values in the error message.
Suggested fix
Clamp the computed value to a minimum of 0: