-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Check API status / Automated retry logic #418
Comments
SO nobody knows? When it ends the usage limit it stops and the app crashes without no errors no returns and i cannot find any way to handle the "Usgae limit reach" |
It should be throwing an error of some kind - so either you need to wrap your calls in try catches, or have a global uncaught error handler registered. I am not aware of any way to check it programatically, but we could potentially build in handling that would retry the request after some delay. |
I'll take a look at getting something like this merged in soon. |
It would be very nice to have the retry logic. I have a large spreadsheet with many worksheets, and cannot read it without hitting a rate limit. Here is my workaround, in case it helps someone while there is no native support for rate limits in the module: // Very rough ad-hoc implementation of https://developers.google.com/sheets/api/limits
const maxBackoff = 32000;
const maxRetries = 16;
let retryNumber = 0;
async function tryDownloadAsCSV(): Promise<ArrayBuffer> {
return await sheet.downloadAsCSV().catch(async (e: AxiosError) => {
if (e.response?.status !== 429) {
throw e;
}
if (++retryNumber > maxRetries) {
throw e;
}
const delay = Math.ceil(Math.min(maxBackoff, 100 + Math.pow(2, retryNumber) * 100) + Math.random() * 100);
console.log(`[${retryNumber} / ${maxRetries}] got 429 from Google Sheets, waiting for ${delay} ms`);
return new Promise(resolve => setTimeout(() => {
resolve(tryDownloadAsCSV());
}, delay));
});
}
const buffer = await tryDownloadAsCSV(); |
I'm using this #525 (comment) as a workaround while the PR is not merged |
Hello! Is it possible to check the API status? How?
For example how many request are made, if i have other available requests, the rate limit per hour, etc?
Thank you!
The text was updated successfully, but these errors were encountered: