Debug: Add detailed logging for Royal Mail API calls
- 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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
40abd3521f
commit
2f123c6b81
@@ -47,14 +47,21 @@ export async function getRoyalMailShippingQuotes(
|
|||||||
// Use live Royal Mail API if credentials available
|
// Use live Royal Mail API if credentials available
|
||||||
const apiKey = process.env.ROYAL_MAIL_API_KEY;
|
const apiKey = process.env.ROYAL_MAIL_API_KEY;
|
||||||
const apiSecret = process.env.ROYAL_MAIL_API_SECRET;
|
const apiSecret = process.env.ROYAL_MAIL_API_SECRET;
|
||||||
|
|
||||||
if (apiKey && apiSecret) {
|
if (apiKey && apiSecret) {
|
||||||
try {
|
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) {
|
} 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
|
// Fall back to estimated rates if API fails
|
||||||
return calculateEstimatedRates(weightKg, isInternational, destinationCountry);
|
return calculateEstimatedRates(weightKg, isInternational, destinationCountry);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('⚠️ Royal Mail API credentials not configured - using estimated rates');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to estimated rates
|
// Fallback to estimated rates
|
||||||
|
|||||||
Reference in New Issue
Block a user