Implement 404 status code to retrieveCourse #1659
Draft
+55
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This PR adds a 404 status code return to
retrieveCoursefunction inControllers/Courses.hswhen the course is not found (in addition to the corresponding 200 status code return when it is).It additionally modifies the tests to include the added status codes, and updates the front-end functions that use the route to the change.
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)
When initially trying to commit, I ran into the issue of an unused variable error, for
TIMEOUT_NAMES_ENUM, from eslint in theGraph.jsfile on the front-end. When I checked the original commit I wasn't sure as to how the change had originally passed eslint.courseography/js/components/graph/Graph.js
Lines 25 to 27 in 7d974d2
From checking the previous commits on master, the only changes between the commit that added this change and now were from dependabot, which to my knowledge didn't affect the eslint configuration. I unfortunately wasn't able to separate the unused variable removal and 404 status code changes into separate commits since committing my main changes without removing the unused variable meant I ran into the same eslint error, so if this change should have been made in a separate pull request I would be happy to fix it.
In addition to modifying the front-end function,
getCourseincomponents/common/utils.js, I modified the functions that called this utility since from what I gathered they did not handle the not found case correctly, although since this was not in the original description let me know if I should revert it.courseography/js/components/common/react_modal.js.jsx
Lines 103 to 112 in 5fe4f9b
courseography/js/components/grid/course_panel.js.jsx
Lines 153 to 165 in 5fe4f9b
Originally, if the course was not found, it would also return
null, which ostensibly causes an error should the old functions try to access a key in the response body. It instead now returns a default value and logs the error on the console; I'm not completely sure if this standard for this project, since from what I saw similar functions on the front-end either did not check error conditions or have a need to in the first place.I've added the status code itself to the tests for the
retrieveCoursefunction, although no other test cases in the application follow a similar pattern, either because they do not return a response with a status code, or because the only status code that they return is 200 so it would be redundant to test it. I was uncertain if this was part of the requested changes, so feel free to let me know should it need to be reverted.To my understanding, this change is a breaking change since it changes the API contract for the
retrieveCoursefunction used by the/courseendpoint in the application, but if this is mislabelled I am happy to fix it.