From e5242589f890b8ce8182b76959b7075da152f97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20M?= Date: Wed, 21 Oct 2020 21:18:21 -0300 Subject: [PATCH] getDeviceCurrentTH: improved error handling --- src/mixins/getDeviceCurrentTH.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/mixins/getDeviceCurrentTH.js b/src/mixins/getDeviceCurrentTH.js index 8dac8ad..aca84de 100644 --- a/src/mixins/getDeviceCurrentTH.js +++ b/src/mixins/getDeviceCurrentTH.js @@ -10,16 +10,12 @@ module.exports = { */ async getDeviceCurrentTH(deviceId, type = '') { const device = await this.getDevice(deviceId); - const error = _get(device, 'error', false); + const temperature = _get(device, 'params.currentTemperature', false); const humidity = _get(device, 'params.currentHumidity', false); - if (error) { - return device; - } - if (!temperature || !humidity) { - return { error: 404, msg: errors.noSensor }; + throw new Error(`${errors.noSensor}`); } const data = { status: 'ok', temperature, humidity };