Skip to content

Commit

Permalink
add retries
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Nov 28, 2024
1 parent 011e87e commit 7955b79
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const crypto = require('crypto');
const qs = require('qs');
const Json2iob = require('json2iob');
const tough = require('tough-cookie');
const axiosRetry = require('axios-retry').default;
class Bmw extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
Expand Down Expand Up @@ -168,6 +169,7 @@ class Bmw extends utils.Adapter {
withCredentials: true,
httpsAgent: new HttpsCookieAgent({ cookies: { jar: this.cookieJar } }),
});
axiosRetry(this.requestClient, { retries: 0 });
}

/**
Expand Down Expand Up @@ -1028,6 +1030,22 @@ class Bmw extends utils.Adapter {
method: 'post',
url: url,
headers: headers,
'axios-retry': {
retries: 3,
// only 403 rate limit
retryCondition: (error) => {
return error.response && error.response.status === 403;
},
retryDelay: () => {
return 5000;
},
onRetry: () => {
this.log.warn('Rate Limit exceeded, retry in 5 seconds');
},
onMaxRetryTimesExceeded: () => {
this.log.error('3 Retries failed');
},
},
})
.then((res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@iobroker/adapter-core": "^3.2.2",
"axios": "^1.7.7",
"axios-retry": "^4.5.0",
"http-cookie-agent": "^6.0.6",
"json-bigint": "^1.0.0",
"json2iob": "^2.6.12",
Expand Down

0 comments on commit 7955b79

Please sign in to comment.