Adding new logging function

This commit is contained in:
2024-03-22 19:01:18 -05:00
parent 6dddc5799f
commit cac674e27a
6 changed files with 69 additions and 6 deletions

View File

@@ -1,7 +1,9 @@
// Need to figoure out expiration and make sure to cycle this appropriately to avoid unnecessary calls
import fetch from "node-fetch";
import { LoggingLevel, smartLogging } from "./helper.js";
const fetchEbayReadToken = async () => {
smartLogging(LoggingLevel.AppTrace, `fetchEbayReadToken`);
const ebayClientId = process.env.EBAY_CLIENT_ID;
const ebayClientSecret = process.env.EBAY_CLIENT_SECRET;
const credentials = Buffer.from(
@@ -9,6 +11,7 @@ const fetchEbayReadToken = async () => {
).toString("base64");
try {
smartLogging(LoggingLevel.Debug, `Fetching Token from eBay`);
const response = await fetch(
"https://api.ebay.com/identity/v1/oauth2/token",
{
@@ -31,7 +34,7 @@ const fetchEbayReadToken = async () => {
const data = await response.json();
return data.access_token;
} catch (error) {
console.error("Error fetching eBay OAuth token:", error);
smartLogging(LoggingLevel.Error, `Error fetching eBay OAuth token: ${error}`);
throw error; // Throw the error to be handled by the caller
}
};