fix(core): handle partial listing data

This commit is contained in:
2026-04-28 21:34:45 -04:00
parent 7966073bf8
commit 3fe5fdb63f
10 changed files with 150 additions and 124 deletions

View File

@@ -274,7 +274,7 @@ function parseEbayListings(
);
// Filter to only elements that actually contain prices (not labels)
const actualPrices: HTMLElement[] = [];
const actualPrices: Element[] = [];
for (const el of allPriceElements) {
const text = el.textContent?.trim();
if (text && EBAY_PRICE_TEXT_RE.test(text) && text.length < 50) {
@@ -301,11 +301,10 @@ function parseEbayListings(
if (nonStrikethroughPrices.length > 0) {
// Use the first non-strikethrough price (sale price)
priceElement = nonStrikethroughPrices[0];
priceElement = nonStrikethroughPrices[0] ?? null;
} else {
// Fallback: use the last price (likely the most current)
const lastPrice = actualPrices[actualPrices.length - 1];
priceElement = lastPrice;
priceElement = actualPrices[actualPrices.length - 1] ?? null;
}
}
}

View File

@@ -86,7 +86,7 @@ interface FacebookMarketplaceItem {
__typename: "GroupCommerceProductItem";
// Listing content
marketplace_listing_title: string;
marketplace_listing_title?: string;
redacted_description?: {
text: string;
};
@@ -99,7 +99,7 @@ interface FacebookMarketplaceItem {
listing_price?: {
amount: string;
currency: string;
amount_with_offset: string;
amount_with_offset?: string;
};
// Location
@@ -127,9 +127,9 @@ interface FacebookMarketplaceItem {
// Seller information
marketplace_listing_seller?: {
__typename: "User";
id: string;
name: string;
__typename?: "User";
id?: string;
name?: string;
profile_picture?: {
uri: string;
};
@@ -1321,6 +1321,14 @@ export async function fetchFacebookItem(
return null;
}
if (itemResponseUrl.includes("unavailable_product=1")) {
logExtractionMetrics(false, itemId);
console.warn(
`Item ${itemId} appears to be sold or removed from marketplace.`,
);
return null;
}
const itemData = extractFacebookItemData(itemHtml);
if (classification.unavailable && !itemData) {