tsvesync 1.0.44 → 1.0.45

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.
@@ -340,9 +340,21 @@ class VeSync {
340
340
  let success = false;
341
341
  try {
342
342
  const [response] = await helpers_1.Helpers.callApi('/cloud/v2/deviceManaged/devices', 'post', helpers_1.Helpers.reqBody(this, 'devicelist'), helpers_1.Helpers.reqHeaders(this), this);
343
- if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.list) {
344
- const deviceList = response.result.list;
345
- success = this.processDevices(deviceList);
343
+ if (!response) {
344
+ logger_1.logger.error('No response received from VeSync API');
345
+ return false;
346
+ }
347
+ if (response.error) {
348
+ logger_1.logger.error('API error:', response.msg || 'Unknown error');
349
+ return false;
350
+ }
351
+ if (!((_a = response.result) === null || _a === void 0 ? void 0 : _a.list)) {
352
+ logger_1.logger.error('No device list found in response');
353
+ return false;
354
+ }
355
+ const deviceList = response.result.list;
356
+ success = this.processDevices(deviceList);
357
+ if (success) {
346
358
  // Log device discovery results
347
359
  logger_1.logger.debug('\n=== Device Discovery Summary ===');
348
360
  logger_1.logger.debug(`Total devices processed: ${deviceList.length}`);
@@ -372,14 +384,19 @@ class VeSync {
372
384
  }
373
385
  logger_1.logger.debug('\n=== End of Device Discovery ===\n');
374
386
  }
387
+ }
388
+ catch (err) {
389
+ const error = err;
390
+ if (error.code === 'ECONNABORTED') {
391
+ logger_1.logger.error('VeSync API request timed out');
392
+ }
393
+ else if (error.code === 'ECONNREFUSED') {
394
+ logger_1.logger.error('Unable to connect to VeSync API');
395
+ }
375
396
  else {
376
- logger_1.logger.error('No devices found in response');
377
- logger_1.logger.error(response.code, response.msg);
397
+ logger_1.logger.error('Error getting device list:', error.message || 'Unknown error');
378
398
  }
379
399
  }
380
- catch (error) {
381
- logger_1.logger.error('Unable to get device list:', error);
382
- }
383
400
  this._inProcess = false;
384
401
  return success;
385
402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "A TypeScript library for interacting with VeSync smart home devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/lib/vesync.ts CHANGED
@@ -419,10 +419,25 @@ export class VeSync {
419
419
  this
420
420
  );
421
421
 
422
- if (response?.result?.list) {
423
- const deviceList = response.result.list;
424
- success = this.processDevices(deviceList);
422
+ if (!response) {
423
+ logger.error('No response received from VeSync API');
424
+ return false;
425
+ }
426
+
427
+ if (response.error) {
428
+ logger.error('API error:', response.msg || 'Unknown error');
429
+ return false;
430
+ }
425
431
 
432
+ if (!response.result?.list) {
433
+ logger.error('No device list found in response');
434
+ return false;
435
+ }
436
+
437
+ const deviceList = response.result.list;
438
+ success = this.processDevices(deviceList);
439
+
440
+ if (success) {
426
441
  // Log device discovery results
427
442
  logger.debug('\n=== Device Discovery Summary ===');
428
443
  logger.debug(`Total devices processed: ${deviceList.length}`);
@@ -455,12 +470,16 @@ export class VeSync {
455
470
  }
456
471
 
457
472
  logger.debug('\n=== End of Device Discovery ===\n');
473
+ }
474
+ } catch (err) {
475
+ const error = err as { code?: string; message?: string };
476
+ if (error.code === 'ECONNABORTED') {
477
+ logger.error('VeSync API request timed out');
478
+ } else if (error.code === 'ECONNREFUSED') {
479
+ logger.error('Unable to connect to VeSync API');
458
480
  } else {
459
- logger.error('No devices found in response');
460
- logger.error(response.code, response.msg);
481
+ logger.error('Error getting device list:', error.message || 'Unknown error');
461
482
  }
462
- } catch (error) {
463
- logger.error('Unable to get device list:', error);
464
483
  }
465
484
 
466
485
  this._inProcess = false;