@@ -70,9 +70,6 @@ public function __construct($client, Collector $collector, Formatter $formatter,
70
70
$ this ->stopwatch = $ stopwatch ;
71
71
}
72
72
73
- /**
74
- * {@inheritdoc}
75
- */
76
73
public function sendAsyncRequest (RequestInterface $ request )
77
74
{
78
75
$ activateStack = true ;
@@ -89,8 +86,8 @@ public function sendAsyncRequest(RequestInterface $request)
89
86
$ this ->collectRequestInformations ($ request , $ stack );
90
87
$ event = $ this ->stopwatch ->start ($ this ->getStopwatchEventName ($ request ), self ::STOPWATCH_CATEGORY );
91
88
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 );
94
91
$ event ->stop ();
95
92
96
93
return $ response ;
@@ -134,13 +131,9 @@ protected function doSendRequest(RequestInterface $request)
134
131
135
132
try {
136
133
$ response = $ this ->client ->sendRequest ($ request );
137
- $ this ->collectResponseInformations ($ response , $ event , $ stack );
134
+ $ this ->collectResponseInformations ($ request , $ response , $ event , $ stack );
138
135
139
136
return $ response ;
140
- } catch (\Exception $ e ) {
141
- $ this ->collectExceptionInformations ($ e , $ event , $ stack );
142
-
143
- throw $ e ;
144
137
} catch (\Throwable $ e ) {
145
138
$ this ->collectExceptionInformations ($ e , $ event , $ stack );
146
139
@@ -150,7 +143,7 @@ protected function doSendRequest(RequestInterface $request)
150
143
}
151
144
}
152
145
153
- private function collectRequestInformations (RequestInterface $ request , Stack $ stack )
146
+ private function collectRequestInformations (RequestInterface $ request , Stack $ stack ): void
154
147
{
155
148
$ uri = $ request ->getUri ();
156
149
$ stack ->setRequestTarget ($ request ->getRequestTarget ());
@@ -162,29 +155,24 @@ private function collectRequestInformations(RequestInterface $request, Stack $st
162
155
$ stack ->setCurlCommand ($ this ->formatter ->formatAsCurlCommand ($ request ));
163
156
}
164
157
165
- private function collectResponseInformations (ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack )
158
+ private function collectResponseInformations (RequestInterface $ request , ResponseInterface $ response , StopwatchEvent $ event , Stack $ stack ): void
166
159
{
167
160
$ stack ->setDuration ($ event ->getDuration ());
168
161
$ stack ->setResponseCode ($ response ->getStatusCode ());
169
- $ stack ->setClientResponse ($ this ->formatter ->formatResponse ($ response ));
162
+ $ stack ->setClientResponse ($ this ->formatter ->formatResponseForRequest ($ response, $ request ));
170
163
}
171
164
172
- private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack )
165
+ private function collectExceptionInformations (\Throwable $ exception , StopwatchEvent $ event , Stack $ stack ): void
173
166
{
174
167
if ($ exception instanceof HttpException) {
175
- $ this ->collectResponseInformations ($ exception ->getResponse (), $ event , $ stack );
168
+ $ this ->collectResponseInformations ($ exception ->getRequest (), $ exception -> getResponse (), $ event , $ stack );
176
169
}
177
170
178
171
$ stack ->setDuration ($ event ->getDuration ());
179
172
$ stack ->setClientException ($ this ->formatter ->formatException ($ exception ));
180
173
}
181
174
182
- /**
183
- * Generates the event name.
184
- *
185
- * @return string
186
- */
187
- private function getStopwatchEventName (RequestInterface $ request )
175
+ private function getStopwatchEventName (RequestInterface $ request ): string
188
176
{
189
177
$ name = sprintf ('%s %s ' , $ request ->getMethod (), $ request ->getUri ());
190
178
0 commit comments