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    public function __construct(TransferException $guzzleException, ?Request $request = null, ?Response $response = null)
24    {
25        $this->_guzzleException = $guzzleException;
26        $message = $this->getErrorMessage($this->getGuzzleException());
27        parent::__construct($message, $request, $response);
28    }
29
30    public function getErrorMessage(TransferException $guzzleException): string
31    {
32        return $guzzleException->getMessage();
33    }
34
35    /**
36     * @return TransferException
37     */
38    public function getGuzzleException(): BaseGuzzleException
39    {
40        return $this->_guzzleException;
41    }
42}
43