ClientHttpException.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\HTTP;
  4. /**
  5. * This exception represents a HTTP error coming from the Client.
  6. *
  7. * By default the Client will not emit these, this has to be explicitly enabled
  8. * with the setThrowExceptions method.
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class ClientHttpException extends \Exception implements HttpException
  15. {
  16. /**
  17. * Response object.
  18. *
  19. * @var ResponseInterface
  20. */
  21. protected $response;
  22. /**
  23. * Constructor.
  24. */
  25. public function __construct(ResponseInterface $response)
  26. {
  27. $this->response = $response;
  28. parent::__construct($response->getStatusText(), $response->getStatus());
  29. }
  30. /**
  31. * The http status code for the error.
  32. */
  33. public function getHttpStatus(): int
  34. {
  35. return $this->response->getStatus();
  36. }
  37. /**
  38. * Returns the full response object.
  39. */
  40. public function getResponse(): ResponseInterface
  41. {
  42. return $this->response;
  43. }
  44. }