feat/parapharmacy-baby-products #31

Open
Ichitux wants to merge 24 commits from feat/parapharmacy-baby-products into main
Showing only changes of commit ee23f61057 - Show all commits
+15 -7
View File
@@ -62,23 +62,31 @@ export async function searchBabyProducts(query) {
action: 'process',
},
timeout: 10000,
validateStatus: (status) => status === 200,
});
if (response.data && response.data.products) {
const products = response.data.products
.map(transformOFFProduct)
.filter(Boolean);
// Check if response is actually JSON (OFF sometimes returns HTML on error)
if (typeof response.data === 'string' || !response.data.products) {
console.warn(`[OFF] Invalid response for "${searchTerm}": API may be down`);
return [];
}
const products = response.data.products
.map(transformOFFProduct)
.filter(Boolean);
// Only cache non-empty results to avoid caching API failures
if (products.length > 0) {
try {
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(products));
console.log(`Cached ${products.length} OFF products for: ${searchTerm}`);
} catch (cacheErr) {
// cache write failed, still return the data
}
return products;
} else {
console.log(`[OFF] No products found for "${searchTerm}", not caching empty result`);
}
return [];
return products;
} catch (error) {
console.error('Error searching baby products from OFF:', error.message);
return [];