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:
@@ -29,7 +29,11 @@ function Feed({ updateCache }) {
|
|||||||
|
|
||||||
for (const newStory of [...newApiStories].reverse()) {
|
for (const newStory of [...newApiStories].reverse()) {
|
||||||
try {
|
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');
|
if (!storyRes.ok) throw new Error('Story fetch failed');
|
||||||
const storyResult = await storyRes.json();
|
const storyResult = await storyRes.json();
|
||||||
const fullStory = storyResult.story;
|
const fullStory = storyResult.story;
|
||||||
@@ -44,7 +48,13 @@ function Feed({ updateCache }) {
|
|||||||
}
|
}
|
||||||
currentStories.unshift(newStory);
|
currentStories.unshift(newStory);
|
||||||
} catch (error) {
|
} 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user