Skip to content

Commit f9900b4

Browse files
authored
Improve error handling (#175)
* Fix undefined error * Fix null error
1 parent 296dd3d commit f9900b4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/switchbot-device.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ class SwitchbotDevice {
443443

444444
this._connect()
445445
.then(() => {
446+
if (!this._chars) {
447+
return reject("No characteristics available.");
448+
}
446449
return this._write(this._chars.write, req_buf);
447450
})
448451
.then(() => {

lib/switchbot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class Switchbot {
132132
for (let addr in peripherals) {
133133
device_list.push(peripherals[addr]);
134134
}
135-
resolve(device_list);
135+
if (device_list.length) {
136+
resolve(device_list);
137+
}
136138
};
137139

138140
// Set a handler for the 'discover' event

0 commit comments

Comments
 (0)