Conversation
This commit adds error handling for reddit 5xx responses that return invalid JSON data, which caused the plugin to fail when retrieving game list from reddit. This fixes issue #28 and #27. This commit also refactors the ASFFreeGamesPlugin class to follow the Single Responsibility Principle, which states that each class should have one responsibility, one single purpose. The main changes are: - Extracted some methods from ASFFreeGamesPlugin to reduce its complexity and increase cohesion. - Moved some methods to other classes where they belong. - Used more idiomatic C# patterns and features, such as string interpolation, var keyword, using statements, null operators, LINQ, async/await, etc. - Added XML documentation comments for public types and members. - Added regular comments for private or complex code blocks. - Added more unit tests to cover the refactored code.
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.
What?
This pull request adds error handling for reddit 5xx responses that return invalid JSON data, which caused the plugin to fail when retrieving game list from ASFInfo. This fixes issue #28 and #27.
This pull request also refactors the ASFFreeGamesPlugin class to follow the Single Responsibility Principle, which states that each class should have one responsibility, one single purpose.
Why?
This error handling is needed to prevent the plugin from crashing or stopping when reddit servers are showing 5xx internal errors, which serve a HTML page instead of JSON payload. This improves the reliability and robustness of the plugin.
This refactoring is needed to make the code easier to understand, modify, and extend in the future. It also helps to avoid potential bugs, errors, or performance issues caused by poorly written or structured code.
How?
This pull request uses the WebBrowser class from ASF to make HTTP requests to reddit and handle the JSON responses. It also uses a custom exception class called RedditServerException to handle the cases where reddit returns a server error with an HTML page instead of a JSON payload. It uses the TryGetPayload method to try to get a JSON object from reddit, and if it fails, it throws the RedditServerException with the status code and the response content.
This pull request applies some code refactoring techniques such as extracting methods, moving methods, using idiomatic C# patterns and features, adding comments and documentation, and adding unit tests.
Testing?
To test this pull request, you need to have ASF running with the plugin enabled. You also need to have some reddit posts with steam keys that are either valid or invalid.
To verify that the refactoring did not break any functionality or introduce any regression, you can do the following steps:
freegamescommand on ASF to start collecting free games from reddit.Screenshots (optional)
N/A
Anything Else?
This pull request does not require any additional changes or dependencies. It is ready to be reviewed and merged into the main branch.