feat: Add 10s timeout and early exit for story preloading on error

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-11-21 00:34:17 +00:00
parent 6cfb4b317f
commit 53468c8ccd

View File

@@ -29,7 +29,11 @@ function Feed({ updateCache }) {
for (const newStory of [...newApiStories].reverse()) {
try {
const storyRes = await fetch('/api/' + newStory.id);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10-second timeout
const storyRes = await fetch('/api/' + newStory.id, { signal: controller.signal });
clearTimeout(timeoutId);
if (!storyRes.ok) throw new Error('Story fetch failed');
const storyResult = await storyRes.json();
const fullStory = storyResult.story;
@@ -44,7 +48,13 @@ function Feed({ updateCache }) {
}
currentStories.unshift(newStory);
} catch (error) {
console.log('Skipping story due to fetch error', newStory.id, error);
if (error.name === 'AbortError') {
console.log('Fetch timed out for story:', newStory.id);
} else {
console.log('Fetch failed for story:', newStory.id, error);
}
setError(true);
break;
}
}