Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more error logging #242

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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