From 7534287f7dc3824ff46476da2a0c7b9289ce0393 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 23 十二月 2024 13:32:02 +0800
Subject: [PATCH] 加入更新日志

---
 thirdPartyApi.js |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/thirdPartyApi.js b/thirdPartyApi.js
index 7aa289f..b508184 100644
--- a/thirdPartyApi.js
+++ b/thirdPartyApi.js
@@ -1,5 +1,7 @@
 // thirdPartyApi.js
 const axios = require('axios');
+
+const logger = require('./logger'); // 根据实际情况调整路径
 // BASIC_API = 'https://hemobs.icoldchain.cn/'
 const BASIC_API = 'http://testbs.ihemodialysis.com/'
 let cachedToken = null;
@@ -28,11 +30,13 @@
 
 // 获取缓存或新的 Token
 async function getCachedOrNewToken() {
+  logger.log('Check if the token exists')
   if (cachedToken && tokenExpiresAt > Date.now()) {
     return cachedToken;
   }
 
   // 如果 token 已经过期或不存在,则重新获取
+  logger.log('If the token has expired or does not exist, retrieve it again')
   const { data, expires_in } = await getAccessToken();
   cachedToken = data;
   tokenExpiresAt = Date.now() + (expires_in - 60) * 1000; // 提前 60 秒刷新 token
@@ -73,6 +77,7 @@
 async function fetchThirdPartyData(url, method = 'GET', headers = {}, data = null, queryParams = {}, pathParams = {}) {
   try {
     const token = await getCachedOrNewToken();
+    logger.info(`get token====${token}`)
     console.log('得到了token------------------------',token)
     const fullUrl = buildUrl(url, pathParams);
 
@@ -89,6 +94,7 @@
 
     return response.data;
   } catch (error) {
+    logger.error('Error fetching third-party data:', error.message)
     console.error('Error fetching third-party data:', error.message);
     throw error;
   }

--
Gitblit v1.8.0