node-red-contrib-remote 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,12 @@ You will find more information on [www.remote-red-com](https://www.remote-red.co
36
36
 
37
37
  ## Version History
38
38
 
39
+ Version 2.0.3
40
+ - More stable handling of connection losses
41
+
42
+ Version 2.0.2
43
+ - Crash on Node-RED startup fixed, extended error reporting
44
+
39
45
  Version 2.0.1
40
46
  - Possible bug on network connection fixed
41
47
 
@@ -12,12 +12,7 @@ module.exports = function(RED) {
12
12
  // Is there a old node.sshprocess object?
13
13
  if (node.sshprocess !== undefined) {
14
14
  node.log(`ssh process with pid ${node.sshprocess.pid} already existing`);
15
- node.sshprocess.removeAllListeners('close');
16
- node.sshprocess.removeAllListeners('exit');
17
- node.sshprocess.removeAllListeners('error');
18
- node.sshprocess.stdout.removeAllListeners('data');
19
- node.sshprocess.stderr.removeAllListeners('data');
20
- node.sshprocess = undefined;
15
+ killSSHProcess(node);
21
16
  }
22
17
 
23
18
  // Reset heartbeat status
@@ -102,7 +97,8 @@ module.exports = function(RED) {
102
97
  return new Promise((resolve, reject) => {
103
98
  // Is this instance banned?
104
99
  if ( node.instanceIsBanned ) {
105
- reject();
100
+ reject(new Error('Instance banned'));
101
+ return;
106
102
  }
107
103
 
108
104
  // Create object with config values to send to server
@@ -120,7 +116,7 @@ module.exports = function(RED) {
120
116
  const configString = JSON.stringify(config);
121
117
  const configStringBuffer = Buffer.from(configString);
122
118
  const configStringBase64 = configStringBuffer.toString('base64');
123
- node.log(`Sending config to server: ${configString}`);
119
+ // node.log(`Sending config to server: ${configString}`);
124
120
 
125
121
  // Call API to retrive server and port.
126
122
  const axiosInstance = commons.createAxiosInstance();
@@ -141,29 +137,39 @@ module.exports = function(RED) {
141
137
  })
142
138
  .catch((error) => {
143
139
  // Log error
144
- node.error('requestInstanceSlot: ' + commons.getNetworkErrorString(error))
140
+ node.error('requestInstanceSlot: ' + commons.getNetworkErrorString(error));
141
+ node.error(error);
145
142
  if ( commons.getNetworkErrorCustomString(error) !== undefined) {
146
143
  node.error(commons.getNetworkErrorCustomString(error));
147
144
  }
145
+ commons.reportError(error, node, 'requestInstanceSlot');
148
146
 
149
147
  // Wenn gebannt -> Merken
150
148
  if ( error.response && error.response.status ) {
151
149
  if ( error.response.status === 403 ) {
152
150
  setStatus(node, {fill:"red",shape:"dot",text:"remote-access.status.banned"});
153
151
  node.instanceIsBanned = true;
152
+ reject(new Error('Instance banned'));
153
+ return;
154
154
  }
155
155
  }
156
156
 
157
157
  // Set status
158
158
  if (!node.instanceIsBanned) setStatus(node, {fill:"red",shape:"dot",text:"remote-access.status.commerror"});
159
- reject();
159
+
160
+ // Resolve as error is handled
161
+ resolve();
160
162
  });
161
163
  });
162
164
  }
163
165
 
164
166
  async function tryConnect(node) {
165
167
  // Request new instance slot and connect ssh
166
- await requestInstanceSlot(node)
168
+ try {
169
+ await requestInstanceSlot(node)
170
+ } catch (error) {
171
+ commons.reportError(error, node, 'tryConnect');
172
+ }
167
173
 
168
174
  // Create timer to check if ssh process still serving in 10 seconds
169
175
  node.checkservingtimeout = setTimeout(checkServing, 1000*10, node);
@@ -210,8 +216,11 @@ module.exports = function(RED) {
210
216
  }
211
217
  node.lastHeartbeatStatus = response.data.status
212
218
 
213
- // If the communication is not ok...
214
- if ( node.lastHeartbeatStatus === 'NOTFOUND' ) {
219
+ // Based on the status...
220
+ if ( node.lastHeartbeatStatus === 'OK' ) {
221
+ node.initialHeartbeatStatus = node.lastHeartbeatStatus; // Wenn es jetzt OK ist, zählt es auch wie initial OK
222
+ setStatus(node, {fill:"green",shape:"dot",text:"remote-access.status.serving"});
223
+ } else if ( node.lastHeartbeatStatus === 'NOTFOUND' ) {
215
224
  // The local endpoint responed a 404...
216
225
  setStatus(node, {fill:"yellow",shape:"dot",text:"remote-access.status.heartbeaterrornotfound"});
217
226
  node.log(`Heartbeat detected no valid endpoint, got a 404 response. Please check the base URL in the connection settings.`);
@@ -219,8 +228,8 @@ module.exports = function(RED) {
219
228
  if ( node.initialHeartbeatStatus === 'OK' ) {
220
229
  // If the status before was ok > Restart communication
221
230
  setStatus(node, {fill:"red",shape:"dot",text:"remote-access.status.heartbeaterror"});
222
- killSSHProcess(node)
223
231
  node.log(`Heartbeat error. Reconnecting soon.`);
232
+ killSSHProcess(node)
224
233
  } else {
225
234
  // If the status before had also an error > Just change the label.
226
235
  setStatus(node, {fill:"yellow",shape:"dot",text:"remote-access.status.heartbeaterroractive"});
@@ -230,7 +239,7 @@ module.exports = function(RED) {
230
239
  })
231
240
  .catch((error) => {
232
241
  // Error on api call > Log error
233
- node.error('heartbeat: ' + commons.getNetworkErrorString(error))
242
+ commons.reportError(error, node, 'heartbeat');
234
243
  if ( commons.getNetworkErrorCustomString(error) !== undefined) {
235
244
  node.error(commons.getNetworkErrorCustomString(error));
236
245
  }
@@ -243,7 +252,13 @@ module.exports = function(RED) {
243
252
  try {
244
253
  if (node.sshprocess !== undefined) {
245
254
  node.log(`Killing process ${node.sshprocess.pid}`);
255
+ node.sshprocess.removeAllListeners('close');
256
+ node.sshprocess.removeAllListeners('exit');
257
+ node.sshprocess.removeAllListeners('error');
258
+ node.sshprocess.stdout.removeAllListeners('data');
259
+ node.sshprocess.stderr.removeAllListeners('data');
246
260
  node.sshprocess.kill();
261
+ node.sshprocess = undefined;
247
262
  }
248
263
  node.serving = false
249
264
  } catch (error) {
@@ -80,6 +80,19 @@ module.exports = {
80
80
  errorString = `Error during DNS queries. Please check Internet connection on your Node-RED server. Please check if a firewall blocks your DNS queries.`;
81
81
  }
82
82
  return errorString;
83
+ },
84
+
85
+ reportError: function(error, node, caller) {
86
+ if (error instanceof AggregateError) {
87
+ error.errors.forEach(errorElem => {
88
+ this.reportError(errorElem, node, caller);
89
+ });
90
+ } else {
91
+ node.error(`${caller}: ${error.code}: ${error.message}`);
92
+ if ( error.stack !== undefined ) {
93
+ node.debug(error.stack);
94
+ }
95
+ }
83
96
  }
84
97
 
85
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-remote",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Remote-RED is an ecosystem to bring remote access, push notification and geofencing to Node-RED. There are also additional functions like directly answer on a notification and homescreen widgets.",
5
5
  "author": "Thorsten Heilmann",
6
6
  "license": "GPL-3.0",
@@ -13,7 +13,7 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "axios": "^1.7.2",
16
+ "axios": "^1.8.1",
17
17
  "internal-ip": "^6.1.0",
18
18
  "limiter": "^1.1.5",
19
19
  "path": "^0.12.7",