1<?php
2
3namespace Elastica\Exception\Connection;
4
5use Elastica\Exception\ConnectionException;
6use Elastica\Request;
7use Elastica\Response;
8use GuzzleHttp\Exception\GuzzleException as BaseGuzzleException;
9use GuzzleHttp\Exception\TransferException;
10
11/**
12 * Transport exception.
13 *
14 * @author Milan Magudia <milan@magudia.com>
15 */
16class GuzzleException extends ConnectionException
17{
18    /**
19     * @var TransferException
20     */
21    protected $_guzzleException;
22
23    /**
24     * @param TransferException $guzzleException
25     * @param Request           $request
26     * @param Response|null     $response
27     */
28    public function __construct(TransferException $guzzleException, Request $request = null, Response $response = null)
29    {
30        $this->_guzzleException = $guzzleException;
31        $message = $this->getErrorMessage($this->getGuzzleException());
32        parent::__construct($message, $request, $response);
33    }
34
35    /**
36     * @param TransferException $guzzleException
37     *
38     * @return string
39     */
40    public function getErrorMessage(TransferException $guzzleException): string
41    {
42        return $guzzleException->getMessage();
43    }
44
45    /**
46     * @return TransferException
47     */
48    public function getGuzzleException(): BaseGuzzleException
49    {
50        return $this->_guzzleException;
51    }
52}
53