Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Apr 29, 2024
1 parent ac0fcc0 commit ebe1437
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,14 @@ class Gruenbeck extends utils.Adapter {
ws.on('error', (error) => {
this.log.error(error);
this.log.info('Reconnect in 5 seconds');
ws.close();
setTimeout(() => {
this.connectMgWebSocket();
}, 5000);
try {
ws.close();
setTimeout(() => {
this.connectMgWebSocket();
}, 5000);
} catch (error) {
this.log.error(error);
}
});
ws.on('message', (data, isBinary) => {
data = isBinary ? data : data.toString();
Expand Down Expand Up @@ -779,10 +783,14 @@ class Gruenbeck extends utils.Adapter {
this.log.error(error);
this.log.error(data);
dataCleaned && this.log.error(dataCleaned);
ws.close();
setTimeout(() => {
this.connectMgWebSocket();
}, 5000);
try {
ws.close();
setTimeout(() => {
this.connectMgWebSocket();
}, 5000);
} catch (error) {
this.log.error(error);
}
}
});
} catch (error) {
Expand Down Expand Up @@ -959,7 +967,11 @@ class Gruenbeck extends utils.Adapter {
clearInterval(clockInterval);
clearInterval(clockInterval);
clearInterval(powerModeInterval);
ws.close();
try {
ws.close();
} catch (error) {
this.log.error(error);
}
//xhr.abort()
this.log.debug('Stopping gruenbeck');
this.setState('info.connection', false, true);
Expand Down

0 comments on commit ebe1437

Please sign in to comment.