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:
@@ -101,8 +101,12 @@ export default function Settings(): JSX.Element {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchGitHubStats = async () => {
|
const fetchGitHubStats = async () => {
|
||||||
const stats = await gitHubStatsService.fetchGitHubStats();
|
try {
|
||||||
setGitHubStats(stats);
|
const stats = await gitHubStatsService.fetchGitHubStats();
|
||||||
|
setGitHubStats(stats);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error fetching GitHub stats:', error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const initAndSetSettings = async () => {
|
const initAndSetSettings = async () => {
|
||||||
@@ -207,29 +211,39 @@ 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 {
|
||||||
const text = await response.text();
|
let response: Response;
|
||||||
const doc = new DOMParser().parseFromString(text, 'text/html');
|
try {
|
||||||
|
response = await fetch(link);
|
||||||
const scraper = new CourseCatalogScraper(SiteSupport.COURSE_CATALOG_DETAILS, doc, link);
|
} catch (e) {
|
||||||
const tableRows = getCourseTableRows(doc);
|
alert(`Failed to fetch url '${link}'`);
|
||||||
const courses = scraper.scrape(tableRows, false);
|
return;
|
||||||
|
|
||||||
if (courses.length === 1) {
|
|
||||||
const description = scraper.getDescription(doc);
|
|
||||||
const row = courses[0]!;
|
|
||||||
const course = row.course!;
|
|
||||||
course.description = description;
|
|
||||||
// console.log(course);
|
|
||||||
|
|
||||||
if (activeSchedule.courses.every(c => c.uniqueId !== course.uniqueId)) {
|
|
||||||
console.log('adding course');
|
|
||||||
addCourse(activeSchedule.id, course);
|
|
||||||
} else {
|
|
||||||
console.log('course already exists');
|
|
||||||
}
|
}
|
||||||
} else {
|
const text = await response.text();
|
||||||
console.log(courses);
|
const doc = new DOMParser().parseFromString(text, 'text/html');
|
||||||
|
|
||||||
|
const scraper = new CourseCatalogScraper(SiteSupport.COURSE_CATALOG_DETAILS, doc, link);
|
||||||
|
const tableRows = getCourseTableRows(doc);
|
||||||
|
const courses = scraper.scrape(tableRows, false);
|
||||||
|
|
||||||
|
if (courses.length === 1) {
|
||||||
|
const description = scraper.getDescription(doc);
|
||||||
|
const row = courses[0]!;
|
||||||
|
const course = row.course!;
|
||||||
|
course.description = description;
|
||||||
|
// console.log(course);
|
||||||
|
|
||||||
|
if (activeSchedule.courses.every(c => c.uniqueId !== course.uniqueId)) {
|
||||||
|
console.log('adding course');
|
||||||
|
addCourse(activeSchedule.id, course);
|
||||||
|
} else {
|
||||||
|
console.log('course already exists');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(courses);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error scraping course:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user