/** * @param Exception $exception * @param string $clientName * @param int $depth */ public function addFailure(Exception $exception, $clientName, $depth) { if ($exception instanceof Exception\HttpException) { $formattedResponse = $this->formatter->formatResponse($exception->getResponse()); } elseif ($exception instanceof Exception\TransferException) { $formattedResponse = $exception->getMessage(); } else { $formattedResponse = sprintf('Unexpected exception of type "%s"', get_class($exception)); } $this->data[$clientName]['response'][$depth][] = $formattedResponse; $this->data[$clientName]['failure'][$depth][] = true; }
/** * {@inheritdoc} */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { $this->logger->info(sprintf('Emit request: "%s"', $this->formatter->formatRequest($request)), ['request' => $request]); return $next($request)->then(function (ResponseInterface $response) use($request) { $this->logger->info(sprintf('Receive response: "%s" for request: "%s"', $this->formatter->formatResponse($response), $this->formatter->formatRequest($request)), ['request' => $request, 'response' => $response]); return $response; }, function (Exception $exception) use($request) { if ($exception instanceof Exception\HttpException) { $this->logger->error(sprintf('Error: "%s" with response: "%s" when emitting request: "%s"', $exception->getMessage(), $this->formatter->formatResponse($exception->getResponse()), $this->formatter->formatRequest($request)), ['request' => $request, 'response' => $exception->getResponse(), 'exception' => $exception]); } else { $this->logger->error(sprintf('Error: "%s" when emitting request: "%s"', $exception->getMessage(), $this->formatter->formatRequest($request)), ['request' => $request, 'exception' => $exception]); } throw $exception; }); }