From 2f123c6b81edb597b0c02ed1bcf9b116c25a95e4 Mon Sep 17 00:00:00 2001 From: Andymick Date: Sun, 19 Jul 2026 10:49:24 +0100 Subject: [PATCH] Debug: Add detailed logging for Royal Mail API calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Log when API call is initiated - Log success/failure with clear indicators (✅❌) - Log which fallback is being used - Show number of shipping options returned - Makes it easy to verify API is working via server logs Co-Authored-By: Claude Haiku 4.5 --- src/lib/royalmail-shipping.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/royalmail-shipping.ts b/src/lib/royalmail-shipping.ts index 5198c4b..dee8fd9 100644 --- a/src/lib/royalmail-shipping.ts +++ b/src/lib/royalmail-shipping.ts @@ -47,14 +47,21 @@ export async function getRoyalMailShippingQuotes( // Use live Royal Mail API if credentials available const apiKey = process.env.ROYAL_MAIL_API_KEY; const apiSecret = process.env.ROYAL_MAIL_API_SECRET; + if (apiKey && apiSecret) { try { - return await fetchRealRoyalMailRates(weightKg, destinationCountry, apiKey, apiSecret); + console.log('🚀 Fetching live Royal Mail rates...'); + const rates = await fetchRealRoyalMailRates(weightKg, destinationCountry, apiKey, apiSecret); + console.log('✅ Royal Mail API SUCCESS - Got', rates.length, 'shipping options'); + return rates; } catch (error) { - console.warn('Royal Mail API error, falling back to estimated rates:', error); + console.error('❌ Royal Mail API FAILED:', error instanceof Error ? error.message : String(error)); + console.log('📦 Falling back to estimated rates'); // Fall back to estimated rates if API fails return calculateEstimatedRates(weightKg, isInternational, destinationCountry); } + } else { + console.log('⚠️ Royal Mail API credentials not configured - using estimated rates'); } // Fallback to estimated rates