get() timeout error after the result was successfully retrieved
Apollon77 opened this issue · 3 comments
Discussed in #613
Originally posted by kardoka November 21, 2022
Greetings, I am getting a timeout error for the get()
command after I successfully process the result of it. What could be the issue here? Would it be possible to handle this error?
The error message (note that I am hiding the device ids and full path to working directory):
node:internal/errors:478
ErrorCaptureStackTrace(err);
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Timeout waiting for status response from device id: hidden)
at new NodeError (node:internal/errors:387:5)
at TuyaDevice.emit (node:events:502:17)
at ./node_modules/tuyapi/index.js:411:12
at Timeout._onTimeout (./node_modules/p-timeout/index.js:25:13)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'ERR_UNHANDLED_ERROR',
context: 'Timeout waiting for status response from device id: hidden
}
The code itself:
const TuyAPI = require('tuyapi');
require('dotenv').config();
const device = new TuyAPI({
id: process.env.GATEWAY_DEVICE_ID,
key: process.env.LOCAL_KEY,
version: 3.3,
issueRefreshOnConnect: true,
});
(async () => {
await device.find();
await device.connect();
let status = await device.get({
cid: process.env.CHILD_ID,
dps: 1
});
console.log(`Current status: ${status}.`);
device.disconnect();
})();
EDIT: I am able to catch it using:
process.on('uncaughtException', error => {
console.log('Caught it!');
})
But is there some more elegant way to catch it or to avoid this exception altogether?
@kardoka basically it is an issue and no discussion, so I created an issue
Please install tuyapi from my Fork (https://github.com/Apollon77/tuyapi) and try if it now works that you get the get response and so not get the exception. Please comment in the PR to tstate if it fixes your issue
Hi, thanks for creating the fork! Sadly I cannot test it because my Tuya Cloud trial has just expired.. I'll test it once I'll sort that out.