Implement 404 status code to retrieveCourse#1659
Draft
a1-su wants to merge 1 commit intoCourseography:masterfrom
Draft
Implement 404 status code to retrieveCourse#1659a1-su wants to merge 1 commit intoCourseography:masterfrom
a1-su wants to merge 1 commit intoCourseography:masterfrom
Conversation
Pull Request Test Coverage Report for Build 21703d1f-38f6-41e1-a1a0-89ca8dc43624Details
💛 - Coveralls |
Contributor
david-yz-liu
left a comment
There was a problem hiding this comment.
Hi @a1-su, great work and thanks for the detailed questions.
- Please make a separate PR for the
eslintchange. But I think it would be worthwhile runningeslinton the entire codebase and fixing any other. I'm not sure how this slipped by the pre-commit hooks, and I'll look into that further. - You're absolutely correct that the existing front-end code didn't check for an error beforehand. I support adding new error-handling logic, but to do so I'd rather have
getCourseraise an error (i.e., no special case for 404), and then in the calling code have a.catchthat resets the state rather than embedding the logic within the.thensuccess callback. Please also add front-end tests for this new logic. - Modifying the
retrieveCoursetests to check status code is great - Because we don't publish the Courseography back-end routes publicly as an official API, we wouldn't consider this a breaking change. I think you can put this under "enhancements" and frame this as improving the error handling behaviour for this route.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.