vendor/guzzlehttp/guzzle/src/Exception/ConnectException.php

54 lines · 1347 bytes

 1<?php
 2
 3namespace GuzzleHttp\Exception;
 4
 5use Psr\Http\Client\NetworkExceptionInterface;
 6use Psr\Http\Message\RequestInterface;
 7
 8/**
 9 * Exception thrown when a connection cannot be established.
10 */
11class ConnectException extends TransferException implements NetworkExceptionInterface
12{
13    /**
14     * @var RequestInterface
15     */
16    private $request;
17
18    /**
19     * @var array
20     */
21    private $handlerContext;
22
23    public function __construct(
24        string $message,
25        RequestInterface $request,
26        ?\Throwable $previous = null,
27        array $handlerContext = []
28    ) {
29        parent::__construct($message, 0, $previous);
30        $this->request = $request;
31        $this->handlerContext = $handlerContext;
32    }
33
34    /**
35     * Get the request that caused the exception
36     */
37    public function getRequest(): RequestInterface
38    {
39        return $this->request;
40    }
41
42    /**
43     * Get contextual information about the error from the underlying handler.
44     *
45     * The contents of this array will vary depending on which handler you are
46     * using. It may also be just an empty array. Relying on this data will
47     * couple you to a specific handler, but can give more debug information
48     * when needed.
49     */
50    public function getHandlerContext(): array
51    {
52        return $this->handlerContext;
53    }
54}