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,10 +1,18 @@
import fetch from "node-fetch";
import fetchEbayReadToken from "../utils/fetchEbayReadToken.js"; // Adjust the import path according to your project structure
import { LoggingLevel, smartLogging } from "../utils/helper.js";
export const itemLookup = async (req, res) => {
smartLogging(LoggingLevel.Debug, ``)
const productCode = req.query.productCode;
const oauthToken = await fetchEbayReadToken();
console.log(productCode);
let oauthToken;
try{
oauthToken = await fetchEbayReadToken();
}catch(e){
smartLogging(LoggingLevel.Error, `Error Getting eBay Token: ${e}`);
}
// console.log(productCode);
smartLogging(LoggingLevel.Logging, `Product Code: ${productCode}`);
try {
const response = await fetch(
`https://api.ebay.com/buy/browse/v1/item_summary/search?gtin=${productCode}`,
@@ -28,7 +36,7 @@ export const itemLookup = async (req, res) => {
res.status(200).send(price);
} catch (error) {
console.error("Error fetching data from eBay Browse API:", error);
smartLogging(LoggingLevel.Error, `Error fetching data from eBay Browse API: ${error}`);
res.status(500).send("Internal Server Error");
}
};