@@ -69,9 +69,6 @@ public function __construct($client, Collector $collector, Formatter $formatter,
6969 $ this ->stopwatch = $ stopwatch ;
7070 }
7171
72- /**
73- * {@inheritdoc}
74- */
7572 public function sendAsyncRequest (RequestInterface $ request )
7673 {
7774 $ activateStack = true ;
@@ -88,8 +85,8 @@ public function sendAsyncRequest(RequestInterface $request)
8885 $ this ->collectRequestInformations ($ request , $ stack );
8986 $ event = $ this ->stopwatch ->start ($ this ->getStopwatchEventName ($ request ), self ::STOPWATCH_CATEGORY );
9087
91- $ onFulfilled = function (ResponseInterface $ response ) use ($ event , $ stack ) {
92- $ this ->collectResponseInformations ($ response , $ event , $ stack );
88+ $ onFulfilled = function (ResponseInterface $ response ) use ($ request , $ event , $ stack ) {
89+ $ this ->collectResponseInformations ($ request , $ response , $ event , $ stack );
9390 $ event ->stop ();
9491
9592 return $ response ;
@@ -133,13 +130,9 @@ protected function doSendRequest(RequestInterface $request)
133130
134131 try {
135132 $ response = $ this ->client ->sendRequest ($ request );
136- $ this ->collectResponseInformations ($ response , $ event , $ stack );
133+ $ this ->collectResponseInformations ($ request , $ response , $ event , $ stack );
137134
138135 return $ response ;
139- } catch (\Exception $ e ) {
140- $ this ->collectExceptionInformations ($ e , $ event , $ stack );
141-
142- throw $ e ;
143136 } catch (\Throwable $ e ) {
144137 $ this ->collectExceptionInformations ($ e , $ event , $ stack );
145138
@@ -149,7 +142,7 @@ protected function doSendRequest(RequestInterface $request)
149142 }
150143 }
151144
152- private function collectRequestInformations (RequestInterface $ request , Stack $ stack )
145+ private function collectRequestInformations (RequestInterface $ request , Stack $ stack ): void
153146 {
154147 $ uri = $ request ->getUri ();
155148 $ stack ->setRequestTarget ($ request ->getRequestTarget ());
@@ -161,29 +154,24 @@ private function collectRequestInformations(RequestInterface $request, Stack $st
161154 $ stack ->setCurlCommand ($ this ->formatter ->formatAsCurlCommand ($ request ));
162155 }
163156
164- private function collectResponseInformations (ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack )
157+ private function collectResponseInformations (RequestInterface $ request , ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack ): void
165158 {
166159 $ stack ->setDuration ($ event ->getDuration ());
167160 $ stack ->setResponseCode ($ response ->getStatusCode ());
168- $ stack ->setClientResponse ($ this ->formatter ->formatResponse ($ response ));
161+ $ stack ->setClientResponse ($ this ->formatter ->formatResponseForRequest ($ response, $ request ));
169162 }
170163
171- private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack )
164+ private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack ): void
172165 {
173166 if ($ exception instanceof HttpException) {
174- $ this ->collectResponseInformations ($ exception ->getResponse (), $ event , $ stack );
167+ $ this ->collectResponseInformations ($ exception ->getRequest (), $ exception -> getResponse (), $ event , $ stack );
175168 }
176169
177170 $ stack ->setDuration ($ event ->getDuration ());
178171 $ stack ->setClientException ($ this ->formatter ->formatException ($ exception ));
179172 }
180173
181- /**
182- * Generates the event name.
183- *
184- * @return string
185- */
186- private function getStopwatchEventName (RequestInterface $ request )
174+ private function getStopwatchEventName (RequestInterface $ request ): string
187175 {
188176 $ name = sprintf ('%s %s ' , $ request ->getMethod (), $ request ->getUri ());
189177
0 commit comments