From 7c87ed33aefbf530025cd391018fbf8fcd93ece8 Mon Sep 17 00:00:00 2001 From: Sheya Bernstein Date: Wed, 28 Feb 2024 20:51:55 +0000 Subject: [PATCH] Improve logging and error handling --- node_helper.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node_helper.js b/node_helper.js index f2c4625..7837711 100644 --- a/node_helper.js +++ b/node_helper.js @@ -66,7 +66,7 @@ module.exports = NodeHelper.create({ try { const response = await fetch(url, { headers }); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + Log.error(`${this.name}: HTTP ${response.status}`); } if ( response.headers @@ -76,12 +76,12 @@ module.exports = NodeHelper.create({ const data = await response.json(); self.sendSocketNotification(notification, data); } else { - throw new Error( - `Expected JSON but received ${response.headers.get("content-type")}`, + Log.error( + `${this.name}: Expected JSON but received ${response.headers.get("content-type")}`, ); } } catch (error) { - Log.error(self.name + " ERROR:", error); + Log.error(`${this.name}: ${error}`) } }, });