diff --git a/api/src/controllers/professors.ts b/api/src/controllers/professors.ts index 1d1b871c..e5d334f2 100644 --- a/api/src/controllers/professors.ts +++ b/api/src/controllers/professors.ts @@ -49,8 +49,12 @@ 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; + 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..b500355c 100644 --- a/site/src/component/GradeDist/GradeDist.tsx +++ b/site/src/component/GradeDist/GradeDist.tsx @@ -54,19 +54,15 @@ const GradeDist: FC = (props) => { }) .then(res => { setGradeDistData(res.data); + }).catch(error => { + setGradeDistData([]); + console.error(error.response); }); } - // initial request to get grade dist data + // reset any data from a previous course or professor, get new data for course or professor useEffect(() => { - if (gradeDistData == null) { - fetchGradeDistData(); - } - }) - - // get new data if choose a new course or professor - useEffect(() => { - setGradeDistData([]); + setGradeDistData(null!); fetchGradeDistData(); }, [props.course?.id, props.professor?.ucinetid]) @@ -239,10 +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. + ); } }