From 2b3275f4f65af2c8b6742469cab80ac3f857451d Mon Sep 17 00:00:00 2001 From: Devin Jean Date: Thu, 23 May 2024 17:50:35 -0500 Subject: [PATCH 1/2] more logging --- src/cloud-client.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cloud-client.js b/src/cloud-client.js index eac7f9be..36938c1c 100644 --- a/src/cloud-client.js +++ b/src/cloud-client.js @@ -1,6 +1,7 @@ const _ = require("lodash"); const fetch = require("node-fetch"); const CacheManager = require("cache-manager"); +const logger = new (require('./logger'))('cloud-client'); const cache = CacheManager.caching({ store: "memory", max: 1000, @@ -57,15 +58,25 @@ class NetsBloxCloud { } async post(urlPath, body) { - const headers = { "Content-Type": "application/json" }; - body = JSON.stringify(body); - return await this.fetch(urlPath, { method: "post", body, headers }); + try { + const headers = { "Content-Type": "application/json" }; + body = JSON.stringify(body); + return await this.fetch(urlPath, { method: "post", body, headers }); + } catch (e) { + logger.error(`failed post request to ${urlPath} (body ${body}) -> cause ${e}`); + throw e; + } } async get(urlPath) { return await cache.wrap(urlPath, async () => { - const response = await this.fetch(urlPath); - return await response.json(); + try { + const response = await this.fetch(urlPath); + return await response.json(); + } catch (e) { + logger.error(`failed get request to ${urlPath} -> cause ${e}`); + throw e; + } }); } From 99bf39a299c7733fa445765755c772609488f643 Mon Sep 17 00:00:00 2001 From: Format Bot Date: Thu, 23 May 2024 22:51:33 +0000 Subject: [PATCH 2/2] Fix code formatting --- src/cloud-client.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cloud-client.js b/src/cloud-client.js index 36938c1c..9a016de9 100644 --- a/src/cloud-client.js +++ b/src/cloud-client.js @@ -1,7 +1,7 @@ const _ = require("lodash"); const fetch = require("node-fetch"); const CacheManager = require("cache-manager"); -const logger = new (require('./logger'))('cloud-client'); +const logger = new (require("./logger"))("cloud-client"); const cache = CacheManager.caching({ store: "memory", max: 1000, @@ -63,7 +63,9 @@ class NetsBloxCloud { body = JSON.stringify(body); return await this.fetch(urlPath, { method: "post", body, headers }); } catch (e) { - logger.error(`failed post request to ${urlPath} (body ${body}) -> cause ${e}`); + logger.error( + `failed post request to ${urlPath} (body ${body}) -> cause ${e}`, + ); throw e; } }