mirror of
https://github.com/Tony0410/readlater.git
synced 2026-05-24 22:01:41 +08:00
Gracefully handle 403 blocked sites with minimal article
Instead of failing completely on 403/401, save a placeholder article with the URL so users can still access via 'Open original' link. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,8 +58,20 @@ export async function extractArticle(url: string): Promise<ExtractedArticle> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 403) {
|
// On 403/blocked, return minimal article with just URL info
|
||||||
throw new Error(`This site blocks automated access (403 Forbidden). Try using the bookmarklet from the article page instead - it can capture content your browser can see.`);
|
if (response.status === 403 || response.status === 401) {
|
||||||
|
const hostname = new URL(url).hostname.replace(/^www\./, "");
|
||||||
|
return {
|
||||||
|
title: `Article from ${hostname}`,
|
||||||
|
author: null,
|
||||||
|
siteName: hostname,
|
||||||
|
excerpt: "This site blocked automated access. Use 'Open original' to read, or the Content Capture bookmarklet to save the full article.",
|
||||||
|
content: `<p>This site blocked automated access. <a href="${url}" target="_blank">Open original article</a> to read.</p><p>Tip: Use the Content Capture bookmarklet from the article page to save the full content.</p>`,
|
||||||
|
textContent: "This site blocked automated access. Open original article to read.",
|
||||||
|
leadImage: null,
|
||||||
|
wordCount: 0,
|
||||||
|
publishedAt: null,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
|
throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user