-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle the rate limit exceeding error #71
Changes from 3 commits
05b9f1b
c327c21
0523a16
b32601c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test/mocks/* -diff linguist-generated=true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,19 @@ const evaluatePending = require('../utils/evaluatePending'); | |
module.exports = async function watch(retryDelay, getResponse) { | ||
const response = await getResponse(); | ||
|
||
const { remaining: remAPIPoints, cost: lastReqCost, resetAt } = response.rateLimit; | ||
const currentTime = new Date(); | ||
const resetTime = new Date(resetAt); | ||
const milliSecondsLeft = resetTime - currentTime; | ||
const secondsLeft = Math.ceil(milliSecondsLeft / 1000); | ||
|
||
if ((remAPIPoints < lastReqCost) && (retryDelay < milliSecondsLeft)) { | ||
process.stderr.write(`API points exhausted. Command will run after ${secondsLeft} seconds\n\n`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it's going to write a newline, can it use |
||
setTimeout(() => { | ||
process.stderr.write('.'); | ||
}, milliSecondsLeft); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this just writes a dot, |
||
} | ||
|
||
const isPendingChecks = evaluatePending(response); | ||
|
||
if (!isPendingChecks) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think console.error should remain here; it plays more nicely with the shell output than process.stderr.write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok! I think I made an error with the closing brackets as well😥