feat: fall back to the browser scraper when the primary fetch fails
- Extract fetchAndExtractPriceViaBrowser from deps (optional) - After primary fetch, if it errors or returns no price and fallback exists, try fallback - Fallback result replaces primary result for further processing - Retry-safety logic unchanged: last_price/last_checked_at only updated on success - All 4 new tests pass, all existing tests unchanged Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gwc3aCiyQxmCWQke8RvEz
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
async function checkProduct(product, deps) {
|
||||
const { fetchAndExtractPrice, sendMail, recordCheckSuccess, recordCheckFailure, now } = deps;
|
||||
const result = await fetchAndExtractPrice(product.url);
|
||||
const {
|
||||
fetchAndExtractPrice, fetchAndExtractPriceViaBrowser,
|
||||
sendMail, recordCheckSuccess, recordCheckFailure, now,
|
||||
} = deps;
|
||||
let result = await fetchAndExtractPrice(product.url);
|
||||
|
||||
if ((result.error || result.price == null) && fetchAndExtractPriceViaBrowser) {
|
||||
result = await fetchAndExtractPriceViaBrowser(product.url);
|
||||
}
|
||||
|
||||
if (result.error) {
|
||||
console.error(`[check] fetch_error "${product.name}" (${product.url}): ${result.error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user