Skip to content

Commit

Permalink
API request throttling optimised
Browse files Browse the repository at this point in the history
  • Loading branch information
bropat committed Aug 20, 2023
1 parent 68bf094 commit 8b31e93
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class HTTPApi extends TypedEmitter<HTTPApiEvents> {
private requestEufyCloud: Got;

private throttle = pThrottle({
limit: 6,
interval: 10000,
limit: 5,
interval: 1000,
});

private devices: FullDevices = {};
Expand Down Expand Up @@ -173,7 +173,11 @@ export class HTTPApi extends TypedEmitter<HTTPApiEvents> {
beforeRetry: [
(options, error, retryCount) => {
// This will be called on `retryWithMergedOptions(...)`
this.log.debug(`Retrying [${retryCount}]: ${error?.code} (${error?.request?.requestUrl})`, { options: options });
const statusCode = error?.response?.statusCode || 0;
const { method, url, prefixUrl } = options;
const shortUrl = getShortUrl(url, prefixUrl);
const body = error?.response?.body ? error?.response?.body : error?.message;
this.log.debug(`Retrying [${retryCount}]: ${error?.code} (${error?.request?.requestUrl})\n${statusCode} ${method} ${shortUrl}\n${body}`);
// Retrying [1]: ERR_NON_2XX_3XX_RESPONSE
}
],
Expand Down

0 comments on commit 8b31e93

Please sign in to comment.