@@ -209,16 +209,7 @@ private function wrapHandler(callable $handler)
209
209
210
210
$ exception = $ this ->getCurlRetryException ($ request , $ response );
211
211
212
- $ this ->logRequestFail (
213
- $ request ['http_method ' ],
214
- $ response ['effective_url ' ],
215
- $ request ['body ' ],
216
- $ request ['headers ' ],
217
- $ response ['status ' ],
218
- $ response ['body ' ],
219
- $ response ['transfer_stats ' ]['total_time ' ],
220
- $ exception
221
- );
212
+ $ this ->logRequestFail ($ request , $ response , $ exception );
222
213
223
214
$ node = $ connection ->getHost ();
224
215
$ this ->log ->warning ("Marking node $ node dead. " );
@@ -254,16 +245,7 @@ private function wrapHandler(callable $handler)
254
245
} else {
255
246
// Something went seriously wrong, bail
256
247
$ exception = new TransportException ($ response ['error ' ]->getMessage ());
257
- $ this ->logRequestFail (
258
- $ request ['http_method ' ],
259
- $ response ['effective_url ' ],
260
- $ request ['body ' ],
261
- $ request ['headers ' ],
262
- $ response ['status ' ],
263
- $ response ['body ' ],
264
- $ response ['transfer_stats ' ]['total_time ' ],
265
- $ exception
266
- );
248
+ $ this ->logRequestFail ($ request , $ response , $ exception );
267
249
throw $ exception ;
268
250
}
269
251
} else {
@@ -285,15 +267,7 @@ private function wrapHandler(callable $handler)
285
267
// No error, deserialize
286
268
$ response ['body ' ] = $ this ->serializer ->deserialize ($ response ['body ' ], $ response ['transfer_stats ' ]);
287
269
}
288
- $ this ->logRequestSuccess (
289
- $ request ['http_method ' ],
290
- $ response ['effective_url ' ],
291
- $ request ['body ' ],
292
- $ request ['headers ' ],
293
- $ response ['status ' ],
294
- $ response ['body ' ],
295
- $ response ['transfer_stats ' ]['total_time ' ]
296
- );
270
+ $ this ->logRequestSuccess ($ request , $ response );
297
271
298
272
return isset ($ request ['client ' ]['verbose ' ]) && $ request ['client ' ]['verbose ' ] === true ? $ response : $ response ['body ' ];
299
273
});
@@ -332,87 +306,76 @@ private function getURI($uri, $params)
332
306
/**
333
307
* Log a successful request
334
308
*
335
- * @param string $method
336
- * @param string $fullURI
337
- * @param string $body
338
- * @param array $headers
339
- * @param string $statusCode
340
- * @param string $response
341
- * @param string $duration
342
- *
309
+ * @param array $request
310
+ * @param array $response
343
311
* @return void
344
312
*/
345
- public function logRequestSuccess ($ method , $ fullURI , $ body , $ headers , $ statusCode , $ response, $ duration )
313
+ public function logRequestSuccess ($ request , $ response )
346
314
{
347
- $ this ->log ->debug ('Request Body ' , array ($ body ));
315
+ $ this ->log ->debug ('Request Body ' , array ($ request [ ' body ' ] ));
348
316
$ this ->log ->info (
349
317
'Request Success: ' ,
350
318
array (
351
- 'method ' => $ method ,
352
- 'uri ' => $ fullURI ,
353
- 'headers ' => $ headers ,
354
- 'HTTP code ' => $ statusCode ,
355
- 'duration ' => $ duration ,
319
+ 'method ' => $ request [ ' http_method ' ] ,
320
+ 'uri ' => $ response [ ' effective_url ' ] ,
321
+ 'headers ' => $ request [ ' headers ' ] ,
322
+ 'HTTP code ' => $ response [ ' status ' ] ,
323
+ 'duration ' => $ response [ ' transfer_stats ' ][ ' total_time ' ] ,
356
324
)
357
325
);
358
- $ this ->log ->debug ('Response ' , array ($ response ));
326
+ $ this ->log ->debug ('Response ' , array ($ response[ ' body ' ] ));
359
327
360
328
// Build the curl command for Trace.
361
- $ curlCommand = $ this ->buildCurlCommand ($ method , $ fullURI , $ body );
329
+ $ curlCommand = $ this ->buildCurlCommand ($ request [ ' http_method ' ] , $ response [ ' effective_url ' ] , $ request [ ' body ' ] );
362
330
$ this ->trace ->info ($ curlCommand );
363
331
$ this ->trace ->debug (
364
332
'Response: ' ,
365
333
array (
366
- 'response ' => $ response ,
367
- 'method ' => $ method ,
368
- 'uri ' => $ fullURI ,
369
- 'HTTP code ' => $ statusCode ,
370
- 'duration ' => $ duration ,
334
+ 'response ' => $ response[ ' body ' ] ,
335
+ 'method ' => $ request [ ' http_method ' ] ,
336
+ 'uri ' => $ response [ ' effective_url ' ] ,
337
+ 'HTTP code ' => $ response [ ' status ' ] ,
338
+ 'duration ' => $ response [ ' transfer_stats ' ][ ' total_time ' ] ,
371
339
)
372
340
);
373
341
}
374
342
375
343
/**
376
344
* Log a failed request
377
345
*
378
- * @param string $method
379
- * @param string $fullURI
380
- * @param string $body
381
- * @param array $headers
382
- * @param null|string $statusCode
383
- * @param null|string $response
384
- * @param string $duration
346
+ * @param array $request
347
+ * @param array $response
385
348
* @param \Exception $exception
386
349
*
387
350
* @return void
388
351
*/
389
- public function logRequestFail ($ method , $ fullURI , $ body , $ headers , $ statusCode , $ response, $ duration , \Exception $ exception )
352
+ public function logRequestFail ($ request , $ response , \Exception $ exception )
390
353
{
391
- $ this ->log ->debug ('Request Body ' , array ($ body ));
354
+ $ this ->log ->debug ('Request Body ' , array ($ request [ ' body ' ] ));
392
355
$ this ->log ->warning (
393
356
'Request Failure: ' ,
394
357
array (
395
- 'method ' => $ method ,
396
- 'uri ' => $ fullURI ,
397
- 'headers ' => $ headers ,
398
- 'HTTP code ' => $ statusCode ,
399
- 'duration ' => $ duration ,
358
+ 'method ' => $ request [ ' http_method ' ] ,
359
+ 'uri ' => $ response [ ' effective_url ' ] ,
360
+ 'headers ' => $ request [ ' headers ' ] ,
361
+ 'HTTP code ' => $ response [ ' status ' ] ,
362
+ 'duration ' => $ response [ ' transfer_stats ' ][ ' total_time ' ] ,
400
363
'error ' => $ exception ->getMessage (),
401
364
)
402
365
);
403
- $ this ->log ->warning ('Response ' , array ($ response ));
366
+ $ this ->log ->warning ('Response ' , array ($ response[ ' body ' ] ));
404
367
405
368
// Build the curl command for Trace.
406
- $ curlCommand = $ this ->buildCurlCommand ($ method , $ fullURI , $ body );
369
+ $ curlCommand = $ this ->buildCurlCommand ($ request [ ' http_method ' ] , $ response [ ' effective_url ' ] , $ request [ ' body ' ] );
407
370
$ this ->trace ->info ($ curlCommand );
408
371
$ this ->trace ->debug (
409
372
'Response: ' ,
410
373
array (
411
374
'response ' => $ response ,
412
- 'method ' => $ method ,
413
- 'uri ' => $ fullURI ,
414
- 'HTTP code ' => $ statusCode ,
415
- 'duration ' => $ duration ,
375
+ 'method ' => $ request [ ' http_method ' ] ,
376
+ 'uri ' => $ response [ ' effective_url ' ] ,
377
+ 'HTTP code ' => $ response [ ' status ' ] ,
378
+ 'duration ' => $ response [ ' transfer_stats ' ][ ' total_time ' ] ,
416
379
)
417
380
);
418
381
}
@@ -620,16 +583,7 @@ private function process4xxError($request, $response, $ignore)
620
583
$ exception = new BadRequest400Exception ($ responseBody , $ statusCode );
621
584
}
622
585
623
- $ this ->logRequestFail (
624
- $ request ['http_method ' ],
625
- $ response ['effective_url ' ],
626
- $ request ['body ' ],
627
- $ request ['headers ' ],
628
- $ response ['status ' ],
629
- $ response ['body ' ],
630
- $ response ['transfer_stats ' ]['total_time ' ],
631
- $ exception
632
- );
586
+ $ this ->logRequestFail ($ request , $ response , $ exception );
633
587
634
588
throw $ exception ;
635
589
}
@@ -666,16 +620,7 @@ private function process5xxError($request, $response, $ignore)
666
620
$ exception = new ServerErrorResponseException ($ responseBody , $ statusCode );
667
621
}
668
622
669
- $ this ->logRequestFail (
670
- $ request ['http_method ' ],
671
- $ response ['effective_url ' ],
672
- $ request ['body ' ],
673
- $ request ['headers ' ],
674
- $ response ['status ' ],
675
- $ response ['body ' ],
676
- $ response ['transfer_stats ' ]['total_time ' ],
677
- $ exception
678
- );
623
+ $ this ->logRequestFail ($ request , $ response , $ exception );
679
624
680
625
throw $ exception ;
681
626
}
0 commit comments