/** * {@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; }); }
/** * @param RequestInterface $request * @param string $clientName * @param int $depth */ public function addRequest(RequestInterface $request, $clientName, $depth) { $this->data[$clientName]['request'][$depth][] = $this->formatter->formatRequest($request); }