Просмотр исходного кода

feat: add enhanced debug logging for ShopRenter API responses #87

Claude 5 месяцев назад
Родитель
Сommit
e17f0d25a1
2 измененных файлов с 26 добавлено и 1 удалено
  1. 13 0
      supabase/functions/_shared/shoprenter-client.ts
  2. 13 1
      supabase/functions/mcp-shoprenter/index.ts

+ 13 - 0
supabase/functions/_shared/shoprenter-client.ts

@@ -590,6 +590,19 @@ export async function shopRenterApiRequest(
     }
     }
 
 
     const data = JSON.parse(response.body)
     const data = JSON.parse(response.body)
+
+    // Debug logging for order queries
+    if (endpoint.includes('/orderExtend')) {
+      console.log('[ShopRenter] Order API response:', {
+        endpoint: path,
+        dataType: Array.isArray(data) ? 'array' : typeof data,
+        itemCount: Array.isArray(data) ? data.length :
+                  (data.data ? data.data.length :
+                  (data.orders ? data.orders.length : 'unknown')),
+        responseKeys: Object.keys(data)
+      })
+    }
+
     return data
     return data
   } catch (error) {
   } catch (error) {
     console.error('[ShopRenter] API request error:', error)
     console.error('[ShopRenter] API request error:', error)

+ 13 - 1
supabase/functions/mcp-shoprenter/index.ts

@@ -264,12 +264,22 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
     // The order_id parameter is actually the innerId from the customer's perspective
     // The order_id parameter is actually the innerId from the customer's perspective
     console.log('[MCP ShopRenter] Fetching order with innerId:', order_id);
     console.log('[MCP ShopRenter] Fetching order with innerId:', order_id);
     const response = await fetchOrders(shop_id, 0, 1, { innerId: order_id });
     const response = await fetchOrders(shop_id, 0, 1, { innerId: order_id });
+
+    console.log('[MCP ShopRenter] Raw response type:', typeof response, Array.isArray(response) ? 'array' : '');
+    console.log('[MCP ShopRenter] Response structure:', {
+      isArray: Array.isArray(response),
+      hasData: !!response?.data,
+      hasOrders: !!response?.orders,
+      responseKeys: response && typeof response === 'object' ? Object.keys(response) : []
+    });
+
     const orders = Array.isArray(response) ? response : (response.data || response.orders || []);
     const orders = Array.isArray(response) ? response : (response.data || response.orders || []);
 
 
     console.log('[MCP ShopRenter] API response:', { ordersCount: orders.length });
     console.log('[MCP ShopRenter] API response:', { ordersCount: orders.length });
 
 
     if (orders.length === 0) {
     if (orders.length === 0) {
       console.warn('[MCP ShopRenter] No order found with innerId:', order_id);
       console.warn('[MCP ShopRenter] No order found with innerId:', order_id);
+      console.log('[MCP ShopRenter] Full response for debugging:', JSON.stringify(response).substring(0, 500));
       return {
       return {
         content: [{
         content: [{
           type: 'text',
           type: 'text',
@@ -278,7 +288,9 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
             debug: {
             debug: {
               shop_id,
               shop_id,
               store_name: store.store_name,
               store_name: store.store_name,
-              searched_innerId: order_id
+              searched_innerId: order_id,
+              responseType: typeof response,
+              responseKeys: response && typeof response === 'object' ? Object.keys(response) : []
             }
             }
           })
           })
         }],
         }],