@@ -70,9 +70,6 @@ public function __construct($client, Collector $collector, Formatter $formatter,
7070 $ this ->stopwatch = $ stopwatch ;
7171 }
7272
73- /**
74- * {@inheritdoc}
75- */
7673 public function sendAsyncRequest (RequestInterface $ request )
7774 {
7875 $ activateStack = true ;
@@ -89,8 +86,8 @@ public function sendAsyncRequest(RequestInterface $request)
8986 $ this ->collectRequestInformations ($ request , $ stack );
9087 $ event = $ this ->stopwatch ->start ($ this ->getStopwatchEventName ($ request ), self ::STOPWATCH_CATEGORY );
9188
92- $ onFulfilled = function (ResponseInterface $ response ) use ($ event , $ stack ) {
93- $ this ->collectResponseInformations ($ response , $ event , $ stack );
89+ $ onFulfilled = function (ResponseInterface $ response ) use ($ request , $ event , $ stack ) {
90+ $ this ->collectResponseInformations ($ request , $ response , $ event , $ stack );
9491 $ event ->stop ();
9592
9693 return $ response ;
@@ -134,13 +131,9 @@ protected function doSendRequest(RequestInterface $request)
134131
135132 try {
136133 $ response = $ this ->client ->sendRequest ($ request );
137- $ this ->collectResponseInformations ($ response , $ event , $ stack );
134+ $ this ->collectResponseInformations ($ request , $ response , $ event , $ stack );
138135
139136 return $ response ;
140- } catch (\Exception $ e ) {
141- $ this ->collectExceptionInformations ($ e , $ event , $ stack );
142-
143- throw $ e ;
144137 } catch (\Throwable $ e ) {
145138 $ this ->collectExceptionInformations ($ e , $ event , $ stack );
146139
@@ -150,7 +143,7 @@ protected function doSendRequest(RequestInterface $request)
150143 }
151144 }
152145
153- private function collectRequestInformations (RequestInterface $ request , Stack $ stack )
146+ private function collectRequestInformations (RequestInterface $ request , Stack $ stack ): void
154147 {
155148 $ uri = $ request ->getUri ();
156149 $ stack ->setRequestTarget ($ request ->getRequestTarget ());
@@ -162,29 +155,24 @@ private function collectRequestInformations(RequestInterface $request, Stack $st
162155 $ stack ->setCurlCommand ($ this ->formatter ->formatAsCurlCommand ($ request ));
163156 }
164157
165- private function collectResponseInformations (ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack )
158+ private function collectResponseInformations (RequestInterface $ request , ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack ): void
166159 {
167160 $ stack ->setDuration ($ event ->getDuration ());
168161 $ stack ->setResponseCode ($ response ->getStatusCode ());
169- $ stack ->setClientResponse ($ this ->formatter ->formatResponse ($ response ));
162+ $ stack ->setClientResponse ($ this ->formatter ->formatResponseForRequest ($ response, $ request ));
170163 }
171164
172- private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack )
165+ private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack ): void
173166 {
174167 if ($ exception instanceof HttpException) {
175- $ this ->collectResponseInformations ($ exception ->getResponse (), $ event , $ stack );
168+ $ this ->collectResponseInformations ($ exception ->getRequest (), $ exception -> getResponse (), $ event , $ stack );
176169 }
177170
178171 $ stack ->setDuration ($ event ->getDuration ());
179172 $ stack ->setClientException ($ this ->formatter ->formatException ($ exception ));
180173 }
181174
182- /**
183- * Generates the event name.
184- *
185- * @return string
186- */
187- private function getStopwatchEventName (RequestInterface $ request )
175+ private function getStopwatchEventName (RequestInterface $ request ): string
188176 {
189177 $ name = sprintf ('%s %s ' , $ request ->getMethod (), $ request ->getUri ());
190178
0 commit comments