Skip to content

Commit

Permalink
feat: stdout error messages for nodejs example codes
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ridrew committed Nov 20, 2024
1 parent e2252ac commit b7a8631
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions examples/nodejs/src/lib/sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@ const call = async (method, path, json) => {
let response;
const URL = [base, path].join(":");
console.log(`calling ${method} ${URL}`);
switch (method) {
case "get":
response = await got
.get(URL, {
enableUnixSockets: true,
})
.json();
break;
case "post":
response = await got
.post(URL, {
enableUnixSockets: true,
json,
})
.json();
break;
default:
throw new Error(`Unsupported method: ${method}`);

try {
switch (method) {
case "get":
response = await got
.get(URL, {
enableUnixSockets: true,
})
.json();
break;
case "post":
response = await got
.post(URL, {
enableUnixSockets: true,
json,
})
.json();
break;
default:
throw new Error(`Unsupported method: ${method}`);
}
return JSON.stringify(response, null, 4);
} catch (error) {
console.error("Error in API call:", error.message);
if (error.response) {
console.error("Error response:", error.response.body);
}
throw error;
}
return JSON.stringify(response, null, 4);
};

export const get = async (path) => call("get", path, null);
Expand Down

0 comments on commit b7a8631

Please sign in to comment.