Skip to content

Commit

Permalink
improve 429 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Nov 26, 2024
1 parent 57c9e61 commit 76fefc4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
14 changes: 6 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1511,20 +1511,18 @@ class Mercedesme extends utils.Adapter {
clearInterval(this.reconnectInterval);
});
this.ws.on("error", (data) => {
this.log.error("WS error:" + data);

this.setState("info.connection", false, true);
try {
if (data.message.indexOf("428") !== -1) {
this.log.warn("Too many requests. Your IP is maybe blocked");
}
if (data.message.indexOf("429") !== -1) {
this.log.warn("Too many requests. Please reduce reconnect");
}
if (data.message.indexOf("403") !== -1) {
} else if (data.message.indexOf("429") !== -1) {
this.log.info("429 Too many requests. The account is blocked until 0:00");
} else if (data.message.indexOf("403") !== -1) {
this.refreshToken(true).catch(() => {
this.log.error("Refresh Token Failed ");
});
} else {
this.log.error("WS error:" + data);
}
} catch (error) {
this.log.error(error);
Expand Down Expand Up @@ -1554,7 +1552,7 @@ class Mercedesme extends utils.Adapter {
setTimeout(() => {
this.connectWS();
}, 2000);
}, 1 * 60 * 1000); //1min
}, 2 * 60 * 1000); //2min
try {
const message = VehicleEvents.PushMessage.deserializeBinary(data).toObject();
if (message.debugmessage) {
Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bundleDependencies": [],
"dependencies": {
"@iobroker/adapter-core": "^3.2.2",
"axios": "^1.7.7",
"axios": "^1.7.8",
"google-protobuf": "^3.21.4",
"json2iob": "^2.6.12",
"request": "^2.88.2",
Expand All @@ -27,10 +27,10 @@
"@eslint/js": "^9.15.0",
"@iobroker/testing": "^5.0.0",
"@tsconfig/node16": "^16.1.3",
"@types/node": "^22.9.0",
"@types/node": "^22.10.0",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"typescript": "~5.6.3"
"typescript": "~5.7.2"
},
"engines": {
"node": ">=16"
Expand Down

0 comments on commit 76fefc4

Please sign in to comment.