ConnectException.php 1.4 KB

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