Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

code improvements

Pedro Ladeira25a63caf515a
diff --git a/apps/web/lib/sitemaps/import-tracked-sitemaps.ts b/apps/web/lib/sitemaps/import-tracked-sitemaps.ts
index 98e9b26bb9..0e9a290c90 100644
--- a/apps/web/lib/sitemaps/import-tracked-sitemaps.ts
+++ b/apps/web/lib/sitemaps/import-tracked-sitemaps.ts
@@ -73,6 +73,11 @@ async function fetchAndParseSitemap(
sitemapUrl: string,
): Promise<SitemapXmlResult> {
const response = await safeFetch(sitemapUrl, undefined, { maxRedirects: 0 });
+ if (!response.ok) {
+ throw new Error(
+ `Failed to fetch sitemap: ${response.status} ${response.statusText}`,
+ );
+ }
const MAX_SITEMAP_BYTES = 10 * 1024 * 1024; // 10 MB
const contentLength = response.headers.get("content-length");
if (contentLength && parseInt(contentLength, 10) > MAX_SITEMAP_BYTES) {
diff --git a/apps/web/tests/misc/import-tracked-sitemaps.test.ts b/apps/web/tests/misc/import-tracked-sitemaps.test.ts
index 0f920b059e..b90c0c2658 100644
--- a/apps/web/tests/misc/import-tracked-sitemaps.test.ts
+++ b/apps/web/tests/misc/import-tracked-sitemaps.test.ts
@@ -297,4 +297,22 @@ describe("crawlSitemapUrls", () => {
expect(urls).toContain("https://example.com/page-1");
});
});
+
+ describe("non-2xx responses", () => {
+ it("reports hadErrors instead of parsing the body on a non-2xx response", async () => {
+ mockContentFetch.mockResolvedValue(
+ makeFetchResponse(
+ Buffer.from(urlsetXml(["https://example.com/page-1"])),
+ 500,
+ ),
+ );
+
+ const { urls, hadErrors } = await crawlSitemapUrls(
+ "https://example.com/sitemap.xml",
+ );
+
+ expect(urls).toEqual([]);
+ expect(hadErrors).toBe(true);
+ });
+ });
});