|
|
@@ -77,7 +77,7 @@ async function syncProducts(
|
|
|
storeId: string,
|
|
|
supabaseAdmin: any,
|
|
|
rateLimiter: RateLimiter
|
|
|
-): Promise<{ synced: number; errors: number }> {
|
|
|
+): Promise<{ synced: number; errors: number; errorMessage?: string }> {
|
|
|
console.log('[WooCommerce] Syncing products...')
|
|
|
let synced = 0
|
|
|
let errors = 0
|
|
|
@@ -137,8 +137,10 @@ async function syncProducts(
|
|
|
|
|
|
console.log(`[WooCommerce] Products sync complete: ${synced} synced, ${errors} errors`)
|
|
|
} catch (error) {
|
|
|
- console.error('[WooCommerce] Product sync error:', error)
|
|
|
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
|
+ console.error('[WooCommerce] Product sync error:', errorMessage, error)
|
|
|
errors++
|
|
|
+ return { synced, errors, errorMessage }
|
|
|
}
|
|
|
|
|
|
return { synced, errors }
|
|
|
@@ -149,7 +151,7 @@ async function syncOrders(
|
|
|
storeId: string,
|
|
|
supabaseAdmin: any,
|
|
|
rateLimiter: RateLimiter
|
|
|
-): Promise<{ synced: number; errors: number }> {
|
|
|
+): Promise<{ synced: number; errors: number; errorMessage?: string }> {
|
|
|
console.log('[WooCommerce] Syncing orders...')
|
|
|
let synced = 0
|
|
|
let errors = 0
|
|
|
@@ -208,8 +210,10 @@ async function syncOrders(
|
|
|
|
|
|
console.log(`[WooCommerce] Orders sync complete: ${synced} synced, ${errors} errors`)
|
|
|
} catch (error) {
|
|
|
- console.error('[WooCommerce] Order sync error:', error)
|
|
|
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
|
+ console.error('[WooCommerce] Order sync error:', errorMessage, error)
|
|
|
errors++
|
|
|
+ return { synced, errors, errorMessage }
|
|
|
}
|
|
|
|
|
|
return { synced, errors }
|
|
|
@@ -220,7 +224,7 @@ async function syncCustomers(
|
|
|
storeId: string,
|
|
|
supabaseAdmin: any,
|
|
|
rateLimiter: RateLimiter
|
|
|
-): Promise<{ synced: number; errors: number }> {
|
|
|
+): Promise<{ synced: number; errors: number; errorMessage?: string }> {
|
|
|
console.log('[WooCommerce] Syncing customers...')
|
|
|
let synced = 0
|
|
|
let errors = 0
|
|
|
@@ -277,8 +281,10 @@ async function syncCustomers(
|
|
|
|
|
|
console.log(`[WooCommerce] Customers sync complete: ${synced} synced, ${errors} errors`)
|
|
|
} catch (error) {
|
|
|
- console.error('[WooCommerce] Customer sync error:', error)
|
|
|
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
|
+ console.error('[WooCommerce] Customer sync error:', errorMessage, error)
|
|
|
errors++
|
|
|
+ return { synced, errors, errorMessage }
|
|
|
}
|
|
|
|
|
|
return { synced, errors }
|
|
|
@@ -446,7 +452,7 @@ serve(async (req) => {
|
|
|
|
|
|
console.log(`[WooCommerce] Starting ${sync_type} sync for store ${store_id}`)
|
|
|
|
|
|
- const syncStats = {
|
|
|
+ const syncStats: any = {
|
|
|
products: { synced: 0, errors: 0 },
|
|
|
orders: { synced: 0, errors: 0 },
|
|
|
customers: { synced: 0, errors: 0 }
|
|
|
@@ -467,6 +473,12 @@ serve(async (req) => {
|
|
|
syncStats.customers = await syncCustomers(store_id, supabaseAdmin, rateLimiter)
|
|
|
}
|
|
|
|
|
|
+ // Collect error messages for better diagnostics
|
|
|
+ const errorMessages = []
|
|
|
+ if (syncStats.products.errorMessage) errorMessages.push(`Products: ${syncStats.products.errorMessage}`)
|
|
|
+ if (syncStats.orders.errorMessage) errorMessages.push(`Orders: ${syncStats.orders.errorMessage}`)
|
|
|
+ if (syncStats.customers.errorMessage) errorMessages.push(`Customers: ${syncStats.customers.errorMessage}`)
|
|
|
+
|
|
|
// Update store alt_data with sync info
|
|
|
const { data: currentStore } = await supabaseAdmin
|
|
|
.from('stores')
|
|
|
@@ -486,7 +498,8 @@ serve(async (req) => {
|
|
|
productsCount: syncStats.products.synced,
|
|
|
ordersCount: syncStats.orders.synced,
|
|
|
customersCount: syncStats.customers.synced,
|
|
|
- lastSyncStats: syncStats
|
|
|
+ lastSyncStats: syncStats,
|
|
|
+ lastSyncErrors: errorMessages.length > 0 ? errorMessages : undefined
|
|
|
}
|
|
|
})
|
|
|
.eq('id', store_id)
|
|
|
@@ -496,6 +509,7 @@ serve(async (req) => {
|
|
|
success: true,
|
|
|
message: `${sync_type} sync completed`,
|
|
|
stats: syncStats,
|
|
|
+ errorMessages: errorMessages.length > 0 ? errorMessages : undefined,
|
|
|
timestamp: new Date().toISOString()
|
|
|
}),
|
|
|
{ status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|