File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,10 @@ public function getContent(bool $throw = true): string
9595 if ($ this ->event && $ this ->event ->isStarted ()) {
9696 $ this ->event ->stop ();
9797 }
98+
99+ if ($ throw ) {
100+ $ this ->checkStatusCode ($ this ->response ->getStatusCode ());
101+ }
98102 }
99103 }
100104
@@ -116,6 +120,10 @@ public function toArray(bool $throw = true): array
116120 if ($ this ->event && $ this ->event ->isStarted ()) {
117121 $ this ->event ->stop ();
118122 }
123+
124+ if ($ throw ) {
125+ $ this ->checkStatusCode ($ this ->response ->getStatusCode ());
126+ }
119127 }
120128 }
121129
Original file line number Diff line number Diff line change 1818use Symfony \Component \HttpClient \Response \MockResponse ;
1919use Symfony \Component \HttpClient \TraceableHttpClient ;
2020use Symfony \Component \Stopwatch \Stopwatch ;
21+ use Symfony \Contracts \HttpClient \Exception \ClientExceptionInterface ;
2122use Symfony \Contracts \HttpClient \HttpClientInterface ;
2223use Symfony \Contracts \HttpClient \Test \TestHttpServer ;
2324
@@ -118,6 +119,18 @@ public function testStream()
118119 $ this ->assertSame ('Symfony is awesome! ' , implode ('' , $ chunks ));
119120 }
120121
122+ public function testToArrayChecksStatusCodeBeforeDecoding ()
123+ {
124+ $ this ->expectException (ClientExceptionInterface::class);
125+
126+ $ sut = new TraceableHttpClient (new MockHttpClient ($ responseFactory = function (): MockResponse {
127+ return new MockResponse ('Errored. ' , ['http_code ' => 400 ]);
128+ }));
129+
130+ $ response = $ sut ->request ('GET ' , 'https://example.com/foo/bar ' );
131+ $ response ->toArray ();
132+ }
133+
121134 public function testStopwatch ()
122135 {
123136 $ sw = new Stopwatch (true );
You can’t perform that action at this time.
0 commit comments