feat: improve error handling with validation and user-friendly messages#22
Open
majiayu000 wants to merge 1 commit intoSthembisoMfusi:mainfrom
Open
feat: improve error handling with validation and user-friendly messages#22majiayu000 wants to merge 1 commit intoSthembisoMfusi:mainfrom
majiayu000 wants to merge 1 commit intoSthembisoMfusi:mainfrom
Conversation
- Add input validation for Pokémon names and IDs - Check for empty strings, invalid characters, and excessive length - Validate numeric IDs are within reasonable range (1-10000) - Improve HTTP error handling with specific messages for: - 404 Not Found: suggestions with example Pokémon names/IDs - 429 Rate Limit: advise waiting before retrying - 500+ Server Errors: explain server-side issues - Connection errors: suggest checking internet connection - Timeout errors: inform about slow server response - Add request timeout (10 seconds) to prevent hanging - Exit with code 1 on errors for proper error signaling - Update existing tests to match new error handling behavior - Add comprehensive unit tests for all new error handling Closes SthembisoMfusi#8 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
This PR addresses Issue #8 by significantly improving error handling in PyDex:
Input validation: Validates Pokémon names/IDs before making API requests
Improved HTTP error handling:
Proper exit codes: Now exits with code 1 on errors for better scripting support
Changes
pokedex.py: Addedvalidate_pokemon_input()function and improvedfetch_pokemon_data()with specific error handlerstest_pokedex.py: Updated to match new error handling behaviortest_error_handling.py: Added comprehensive unit tests (24 tests) covering all new functionalityTest plan
Closes #8
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com