How to Catch Rate Limit errors?
See original GitHub issueHi,
we use your great nodejs library to integrate with Google Drive. We wrap your library basically in https://github.com/simatec/ioBroker.backitup/blob/master/lib/googleDriveLib.js
Now we have some users that alw<ys get Rate Limiting errors and in fact these are ok, but something seems to be wrong because they are thrown as unhandled promise rejections in the end and are not catchable. I also did a dive through your code and basically yes it should work, but we still get these reports and also our Sentry instance shows them:
One case: https://sentry.iobroker.net/share/issue/cdcb2ff3d08042f7829bb551e73a7043/
Error: User Rate Limit Exceeded. Rate of requests for user exceed configured project quota. You may consider re-evaluating expected per-user traffic to the API and adjust project quota limits accordingly. You may monitor aggregate quota usage and adjust lim...
File "/opt/iobroker/node_modules/gaxios/src/gaxios.ts", line 117, col 15, in Gaxios._request
?, in runMicrotasks
File "internal/process/task_queues.js", line 97, col 5, in processTicksAndRejections
File "/opt/iobroker/node_modules/google-auth-library/build/src/auth/oauth2client.js", line 343, col 18, in OAuth2Client.requestAsync
r2 = await this.transporter.request(opts);
Second case: https://sentry.iobroker.net/share/issue/a325278331b14b81ac79337e65a6be86/
Error: Rate Limit Exceeded
File "/opt/iobroker/node_modules/iobroker.backitup/node_modules/gaxios/src/gaxios.ts", line 117, col 15, in Gaxios._request
File "internal/process/next_tick.js", line 68, col 7, in process._tickCallback
We use the most current version of googleaps here: 59.0.0
In fact yes we need to optimize the timing when (as it seems) we delete many files (https://github.com/simatec/ioBroker.backitup/blob/master/lib/scripts/75-googledrive.js#L43 …) but in fact the error should come to the callback as expected and should not be uncatchable thrown …
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
@Apollon77 https://github.com/googleapis/google-api-nodejs-client/issues/2495
Greetings! I took a look at your code, and it has a few issues that could be leading to the problem here. Your code is mixing promises and call backs in some confusing ways. This code:
Could be simplified to:
When you call one of these methods as a promise, whether with
.then
chaining orasync
functions, it’s going to throw if you hit an exception. If you want to handle specific cases, you can always wrap this in atry
/catch
, and then look forerr.response.status
, which should tell you what caused this specific problem.