Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Handling for parse() in get_user_by_id_handler and update_contest_score_handler #6

Merged

Conversation

HarshitShukla-dev
Copy link
Contributor

This PR addresses issue #4 by improving error handling in the get_user_by_id_handler and update_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 the parse() operation.

  • In the get_user_by_id_handler function, ID parsing is now handled with proper error checking instead of using unwrap(). If the parsing fails, a 400 Bad Request response is returned, providing a clear error message. Additionally, the function now responds with a 404 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 a 400 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.

- Replaced `unwrap()` with proper error handling for parsing ID
- Return 400 Bad Request if ID parsing fails
- Return detailed error message if database query fails
- Added handling for case when user is not found in the database
- Replaced `unwrap()` with robust error handling for ID parsing
- Return 400 Bad Request if ID parsing fails
- Added error handling for database update failures
- Improved response messages for missing user cases
@Sidharth-Singh10
Copy link
Owner

Great work!! @HarshitShukla-dev

@Sidharth-Singh10 Sidharth-Singh10 merged commit e6a74db into Sidharth-Singh10:main Oct 1, 2024
4 checks passed
@HarshitShukla-dev HarshitShukla-dev deleted the add-error-handling branch October 2, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants