forked from tanner/qotnews
fix: Provide detailed error messages for network failures
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -6,7 +6,7 @@ import { sourceLink, infoLine, logos } from './utils.js';
|
|||||||
|
|
||||||
function Feed({ updateCache }) {
|
function Feed({ updateCache }) {
|
||||||
const [stories, setStories] = useState(() => JSON.parse(localStorage.getItem('stories')) || false);
|
const [stories, setStories] = useState(() => JSON.parse(localStorage.getItem('stories')) || false);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch('/api')
|
fetch('/api')
|
||||||
@@ -48,12 +48,15 @@ function Feed({ updateCache }) {
|
|||||||
}
|
}
|
||||||
currentStories.unshift(newStory);
|
currentStories.unshift(newStory);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
let errorMessage;
|
||||||
if (error.name === 'AbortError') {
|
if (error.name === 'AbortError') {
|
||||||
|
errorMessage = `The request to fetch story '${newStory.title}' (${newStory.id}) timed out after 10 seconds. Your connection may be unstable.`;
|
||||||
console.log('Fetch timed out for story:', newStory.id);
|
console.log('Fetch timed out for story:', newStory.id);
|
||||||
} else {
|
} else {
|
||||||
|
errorMessage = `An error occurred while fetching story '${newStory.title}' (${newStory.id}): ${error.toString()}`;
|
||||||
console.log('Fetch failed for story:', newStory.id, error);
|
console.log('Fetch failed for story:', newStory.id, error);
|
||||||
}
|
}
|
||||||
setError(true);
|
setError(errorMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +72,8 @@ function Feed({ updateCache }) {
|
|||||||
setStories(finalStories);
|
setStories(finalStories);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
setError(true);
|
const errorMessage = `Failed to fetch the main story list from the API. Your connection may be down or the server might be experiencing issues. Error: ${error.toString()}`;
|
||||||
|
setError(errorMessage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, [updateCache]);
|
}, [updateCache]);
|
||||||
|
|||||||
Reference in New Issue
Block a user