maxisoft / ASFFreeGames

Collect free steam games while asf is running
GNU Affero General Public License v3.0
121 stars 2 forks source link

Handle reddit 5xx errors and refactor ASFFreeGamesPlugin class #31

Closed maxisoft closed 10 months ago

maxisoft commented 10 months ago

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:

  1. Run freegames command on ASF to start collecting free games from reddit.
  2. Check the console output or the log file for any errors or warnings related to the plugin or ASF.
  3. Confirm that the plugin successfully adds valid steam keys to your account.
  4. Confirm that the plugin handles invalid steam keys gracefully without crashing or stopping.

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.