Skip to content

Handle reddit 5xx errors and refactor ASFFreeGamesPlugin class#31

Merged
maxisoft merged 2 commits intomainfrom
refactor
Aug 14, 2023
Merged

Handle reddit 5xx errors and refactor ASFFreeGamesPlugin class#31
maxisoft merged 2 commits intomainfrom
refactor

Conversation

@maxisoft
Copy link
Owner

@maxisoft maxisoft commented Aug 14, 2023

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.

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.
@maxisoft maxisoft self-assigned this Aug 14, 2023
@maxisoft maxisoft merged commit 2fe50d6 into main Aug 14, 2023
@maxisoft maxisoft deleted the refactor branch August 14, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when retrieving game list JSON data from reddit Games don't add up

1 participant