Skip to content

Commit

Permalink
more error logging (#242)
Browse files Browse the repository at this point in the history
* more logging

* Fix code formatting

---------

Co-authored-by: Format Bot <[email protected]>
  • Loading branch information
dragazo and Format Bot authored May 24, 2024
1 parent be2dcb2 commit 96e82c3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/cloud-client.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -57,15 +58,27 @@ 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;
}
});
}

Expand Down

0 comments on commit 96e82c3

Please sign in to comment.