fix: preserve ebay rate-limit fallback
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
ensureCookies,
|
ensureCookies,
|
||||||
formatCookiesForHeader,
|
formatCookiesForHeader,
|
||||||
} from "../utils/cookies";
|
} from "../utils/cookies";
|
||||||
import { fetchHtml, HttpError } from "../utils/http";
|
import { fetchHtml, HttpError, RateLimitError } from "../utils/http";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
import { classifyUnstableListings } from "../utils/unstable";
|
import { classifyUnstableListings } from "../utils/unstable";
|
||||||
|
|
||||||
@@ -511,9 +511,9 @@ export default async function fetchEbayItems(
|
|||||||
logger.log(`Parsed ${filteredListings.length} eBay listings.`);
|
logger.log(`Parsed ${filteredListings.length} eBay listings.`);
|
||||||
return finalizeResults(filteredListings);
|
return finalizeResults(filteredListings);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof HttpError) {
|
if (err instanceof HttpError || err instanceof RateLimitError) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Failed to fetch eBay search (${err.statusCode}): ${err.message}`,
|
`Failed to fetch eBay search (${err instanceof HttpError ? err.statusCode : 429}): ${err.message}`,
|
||||||
);
|
);
|
||||||
return finalizeResults([]);
|
return finalizeResults([]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,21 @@ describe("eBay Scraper Cookie Handling", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("returns empty results when eBay rate-limits the request", async () => {
|
||||||
|
global.fetch = mock(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
ok: false,
|
||||||
|
status: 429,
|
||||||
|
headers: { get: () => "0" },
|
||||||
|
text: () => Promise.resolve(""),
|
||||||
|
}),
|
||||||
|
) as unknown as typeof fetch;
|
||||||
|
|
||||||
|
const results = await fetchEbayItems("laptop", 1000);
|
||||||
|
|
||||||
|
expect(results).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
test("deduplicates repeated item links from the same card", async () => {
|
test("deduplicates repeated item links from the same card", async () => {
|
||||||
global.fetch = mock(() =>
|
global.fetch = mock(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
|
|||||||
Reference in New Issue
Block a user