From 4fe528fccfb25c679e3963c0610787147f828065 Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 15 Apr 2023 14:15:22 -0700 Subject: [PATCH 1/5] Pass status code for grades requests to avoid crashes. Print errors --- api/src/controllers/professors.ts | 9 +++++++-- site/src/component/GradeDist/GradeDist.tsx | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/src/controllers/professors.ts b/api/src/controllers/professors.ts index 1d1b871c..d5329793 100644 --- a/api/src/controllers/professors.ts +++ b/api/src/controllers/professors.ts @@ -49,8 +49,13 @@ router.post('/api/batch', (req: Request<{}, {}, { professors: string[] }>, res) router.get('/api/grades/:name', function (req, res, next) { let r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?instructor=' + encodeURIComponent(req.params.name)); - r.then((response) => response.json()) - .then((data) => res.send(data)) + let status = 200; + + r.then((response) => { + status = response.status; + console.log(status); + return response.json(); + }).then((data) => res.status(status).send(data)) }); export default router; \ No newline at end of file diff --git a/site/src/component/GradeDist/GradeDist.tsx b/site/src/component/GradeDist/GradeDist.tsx index b87fdd03..a7f35af5 100644 --- a/site/src/component/GradeDist/GradeDist.tsx +++ b/site/src/component/GradeDist/GradeDist.tsx @@ -54,6 +54,9 @@ const GradeDist: FC = (props) => { }) .then(res => { setGradeDistData(res.data); + }).catch(error => { + // TODO: display an error message + console.error(error.response); }); } From 891daa1946586ae395cabfb23b0642a1c60ddb97 Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 22 Apr 2023 13:41:54 -0700 Subject: [PATCH 2/5] Simple grade dist error msg --- site/src/component/GradeDist/GradeDist.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/src/component/GradeDist/GradeDist.tsx b/site/src/component/GradeDist/GradeDist.tsx index a7f35af5..04fcf201 100644 --- a/site/src/component/GradeDist/GradeDist.tsx +++ b/site/src/component/GradeDist/GradeDist.tsx @@ -55,7 +55,6 @@ const GradeDist: FC = (props) => { .then(res => { setGradeDistData(res.data); }).catch(error => { - // TODO: display an error message console.error(error.response); }); } @@ -245,6 +244,7 @@ const GradeDist: FC = (props) => { } else { return (
+ Error: could not retrieve grade distribution data.
); } From 27a4a904b6e12fab7ebac392f31316b2885f032d Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 22 Apr 2023 13:44:17 -0700 Subject: [PATCH 3/5] Remove status log from professor grades endpoint --- api/src/controllers/professors.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/controllers/professors.ts b/api/src/controllers/professors.ts index d5329793..e5d334f2 100644 --- a/api/src/controllers/professors.ts +++ b/api/src/controllers/professors.ts @@ -53,7 +53,6 @@ router.get('/api/grades/:name', function (req, res, next) { r.then((response) => { status = response.status; - console.log(status); return response.json(); }).then((data) => res.status(status).send(data)) }); From 8b0328ca58f39e1cad96932bf8e0bd829f527d79 Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 22 Apr 2023 13:51:13 -0700 Subject: [PATCH 4/5] Remove unnecessary double call for grade dist data --- site/src/component/GradeDist/GradeDist.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/site/src/component/GradeDist/GradeDist.tsx b/site/src/component/GradeDist/GradeDist.tsx index 04fcf201..e68d6265 100644 --- a/site/src/component/GradeDist/GradeDist.tsx +++ b/site/src/component/GradeDist/GradeDist.tsx @@ -59,14 +59,7 @@ const GradeDist: FC = (props) => { }); } - // initial request to get grade dist data - useEffect(() => { - if (gradeDistData == null) { - fetchGradeDistData(); - } - }) - - // get new data if choose a new course or professor + // reset any data from a previous course or professor, get new data for course or professor useEffect(() => { setGradeDistData([]); fetchGradeDistData(); From 98ecf93ff3ed4c0a4d49a6baa8f74a1706d6f7a4 Mon Sep 17 00:00:00 2001 From: Jacob Sommer Date: Sat, 22 Apr 2023 14:04:19 -0700 Subject: [PATCH 5/5] Show nothing while grade dist data is being fetched. Show error if the fetch fails --- site/src/component/GradeDist/GradeDist.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/site/src/component/GradeDist/GradeDist.tsx b/site/src/component/GradeDist/GradeDist.tsx index e68d6265..b500355c 100644 --- a/site/src/component/GradeDist/GradeDist.tsx +++ b/site/src/component/GradeDist/GradeDist.tsx @@ -55,13 +55,14 @@ const GradeDist: FC = (props) => { .then(res => { setGradeDistData(res.data); }).catch(error => { + setGradeDistData([]); console.error(error.response); }); } // reset any data from a previous course or professor, get new data for course or professor useEffect(() => { - setGradeDistData([]); + setGradeDistData(null!); fetchGradeDistData(); }, [props.course?.id, props.professor?.ucinetid]) @@ -234,11 +235,13 @@ const GradeDist: FC = (props) => { ); - } else { + } else if (gradeDistData == null) { // null if still fetching, don't display anything while it still loads + return null; + } else { // gradeDistData is empty, did not receive any data from API call or received an error, display an error message return ( -
+ <> Error: could not retrieve grade distribution data. -
+ ); } }