Skip to content

Rename HttpException to ClientException#909

Merged
jtojnar merged 13 commits intosimplepie:masterfrom
Art4:rename-httpexception-to-clientexception
Jun 25, 2025
Merged

Rename HttpException to ClientException#909
jtojnar merged 13 commits intosimplepie:masterfrom
Art4:rename-httpexception-to-clientexception

Conversation

@Art4
Copy link
Contributor

@Art4 Art4 commented Jan 14, 2025

This PR renames the SimplePie\Exception\HttpException to SimplePie\HTTP\ClientException to avoid confusion (#905) that this exception is thrown on an 4xx or 5xx response from the server. Because the ClientException is always catched internally I marked the class as @internal.

This PR also adds tests to show that the responses (File or Psr7Response class) always contains the status code, even if it is 429.

Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and sorry for the delay in the review.

The renaming is reasonable but the file test is misleading as FileClient behaves differently from Psr18Client. For now, I would probably mark the test as incomplete, and fix the behaviour in later PR.

adds a webserver mock for integration tests
@Art4 Art4 requested a review from jtojnar June 25, 2025 07:48
@Art4
Copy link
Contributor Author

Art4 commented Jun 25, 2025

I've added an integration test with a mocked webserver using https://github.com/donatj/mock-webserver.

@jtojnar As you correctly said here we can check in the FileClient for $file->get_status_code() === 0 to decide whether an exception should be thrown or not.

Art4 added 2 commits June 25, 2025 20:48
use Mock instead of stub to make sure the get_status_code() method is called
@Art4 Art4 requested a review from jtojnar June 25, 2025 19:25
Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect now. Suggest squash-merging with the following message:

Rename HttpException to ClientException and stop throwing on HTTP error in FileClient

This PR renames the `SimplePie\Exception\HttpException` to `SimplePie\HTTP\ClientException` to avoid confusion (https://github.com/simplepie/simplepie/pull/905) that this exception is thrown on an 4xx or 5xx response from the server. Because the `ClientException` is always caught internally, I marked the class as `@internal`.

Additionally, change the `FileClient` to only throw the exception on non-HTTP errors to match PSR-18 and our `Psr18Client`. This is not a BC break since this API is not part of any release yet.

Also add unit tests to show that the responses (`File` or `Psr7Response` class) always contain the status code, even if it is 429. Plus integration tests using a HTTP server.

@Art4
Copy link
Contributor Author

Art4 commented Jun 25, 2025

👍 Please proceed as you like.

@jtojnar jtojnar merged commit 4f5194b into simplepie:master Jun 25, 2025
10 checks passed
@jtojnar jtojnar modified the milestone: 1.9.0 Jun 25, 2025
@Art4 Art4 deleted the rename-httpexception-to-clientexception branch June 25, 2025 23:36
Alkarex added a commit to Alkarex/simplepie that referenced this pull request Aug 1, 2025
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Aug 1, 2025
Alkarex added a commit to FreshRSS/FreshRSS that referenced this pull request Aug 1, 2025
* Bump SimplePie with PHPStan Level 8
* FreshRSS/simplepie#45
SimplePie increased to PHPStan Level 8:
* simplepie/simplepie#857

* Merge upstream
Including my two PRs:
* simplepie/simplepie#932
* simplepie/simplepie#933

* Resolve upstream sync of Expose HTTP status
* FreshRSS/simplepie#47
Finalise merge, following:
* simplepie/simplepie#905 (comment)
* simplepie/simplepie#909
* #7038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants