fix: add a little error checking to settings (#315)

* fix: add a little error checking to settings

* fix: add a little more
This commit is contained in:
Razboy20
2024-10-16 22:16:17 -05:00
committed by GitHub
parent 5634fbed8a
commit e261641e59

View File

@@ -101,8 +101,12 @@ export default function Settings(): JSX.Element {
useEffect(() => { useEffect(() => {
const fetchGitHubStats = async () => { const fetchGitHubStats = async () => {
try {
const stats = await gitHubStatsService.fetchGitHubStats(); const stats = await gitHubStatsService.fetchGitHubStats();
setGitHubStats(stats); setGitHubStats(stats);
} catch (error) {
console.warn('Error fetching GitHub stats:', error);
}
}; };
const initAndSetSettings = async () => { const initAndSetSettings = async () => {
@@ -207,7 +211,14 @@ export default function Settings(): JSX.Element {
// Exit if the user cancels the prompt // Exit if the user cancels the prompt
if (link === null) return; if (link === null) return;
const response = await fetch(link); try {
let response: Response;
try {
response = await fetch(link);
} catch (e) {
alert(`Failed to fetch url '${link}'`);
return;
}
const text = await response.text(); const text = await response.text();
const doc = new DOMParser().parseFromString(text, 'text/html'); const doc = new DOMParser().parseFromString(text, 'text/html');
@@ -231,6 +242,9 @@ export default function Settings(): JSX.Element {
} else { } else {
console.log(courses); console.log(courses);
} }
} catch (error) {
console.error('Error scraping course:', error);
}
}; };
const [devMode, toggleDevMode] = useDevMode(10); const [devMode, toggleDevMode] = useDevMode(10);