Improve Error Handling for parse() in get_user_by_id_handler and update_contest_score_handler #6
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.
This PR addresses issue #4 by improving error handling in the
get_user_by_id_handler
andupdate_contest_score_handler
functions, which previously used.parse().unwrap()
to convert a string to an integer. The use of.unwrap()
could cause the application to panic if the string was not a valid integer. To prevent this, I have replaced.parse().unwrap()
with proper error handling that checks the result of theparse()
operation.In the
get_user_by_id_handler
function, ID parsing is now handled with proper error checking instead of usingunwrap()
. If the parsing fails, a400 Bad Request
response is returned, providing a clear error message. Additionally, the function now responds with a404 Not Found
status when no user is found in the database.Similarly, in the
update_contest_score_handler
, ID parsing is improved with proper error handling, returning a400 Bad Request
response for invalid input. The function also handles database update failures more gracefully and returns more descriptive responses when the user is missing.