File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88## [ Unreleased]
99
1010### Changed
11- - Add isPermaLink=false support to setPublicId() - (#103 )
11+ - Add isPermaLink=false support to setPublicId() (#103 )
12+ - Return better error messages when remote responds with error code (#146 )
1213
1314### Fixed
1415- fix: rewrite relative links in ` content:encoded ` and other optional elements, not only in ` content ` /` description ` properties
Original file line number Diff line number Diff line change @@ -12,10 +12,15 @@ public function __construct(
1212 protected ResponseInterface $ response ,
1313 float $ duration = 0
1414 ) {
15- parent ::__construct (
16- 'internal server error ' ,
17- $ duration
15+ $ statusCode = $ response ->getStatusCode ();
16+ $ reasonPhrase = trim ($ response ->getReasonPhrase ());
17+ $ message = sprintf (
18+ 'Server responded with: %d%s ' ,
19+ $ statusCode ,
20+ $ reasonPhrase !== '' ? ' ' . $ reasonPhrase : ''
1821 );
22+
23+ parent ::__construct ($ message , $ duration );
1924 }
2025
2126 public function getResponse (): ResponseInterface
Original file line number Diff line number Diff line change @@ -105,6 +105,22 @@ public function testGetResponseThrowsServerErrorOnServerError(): void
105105 ->willReturn ($ psrResponse );
106106
107107 $ this ->expectException (ServerErrorException::class);
108+ $ this ->expectExceptionMessage ('Server responded with: 500 Internal Server Error ' );
109+
110+ $ this ->client ->getResponse ('https://example.com/feed.xml ' );
111+ }
112+
113+ public function testGetResponseThrowsServerErrorOnForbidden (): void
114+ {
115+ $ psrResponse = new PsrResponse (403 , [], 'Forbidden ' );
116+
117+ $ this ->psrClient
118+ ->expects ($ this ->once ())
119+ ->method ('sendRequest ' )
120+ ->willReturn ($ psrResponse );
121+
122+ $ this ->expectException (ServerErrorException::class);
123+ $ this ->expectExceptionMessage ('Server responded with: 403 Forbidden ' );
108124
109125 $ this ->client ->getResponse ('https://example.com/feed.xml ' );
110126 }
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ protected function getClientMock()
5252 protected function getFaultyClientMock ()
5353 {
5454 $ response = $ this ->createMock ('Psr\Http\Message\ResponseInterface ' );
55+ $ response ->method ('getStatusCode ' )->willReturn (403 );
56+ $ response ->method ('getReasonPhrase ' )->willReturn ('Forbidden ' );
57+
5558 $ client = $ this ->createMock ('FeedIo\Adapter\ClientInterface ' );
5659 $ client ->expects ($ this ->any ())->method ('getResponse ' )->willThrowException (
5760 new ServerErrorException ($ response , 0 )
You can’t perform that action at this time.
0 commit comments