Exception.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Exception for HTTP requests
  4. *
  5. * @package Requests\Exceptions
  6. */
  7. namespace WpOrg\Requests;
  8. use Exception as PHPException;
  9. /**
  10. * Exception for HTTP requests
  11. *
  12. * @package Requests\Exceptions
  13. */
  14. class Exception extends PHPException {
  15. /**
  16. * Type of exception
  17. *
  18. * @var string
  19. */
  20. protected $type;
  21. /**
  22. * Data associated with the exception
  23. *
  24. * @var mixed
  25. */
  26. protected $data;
  27. /**
  28. * Create a new exception
  29. *
  30. * @param string $message Exception message
  31. * @param string $type Exception type
  32. * @param mixed $data Associated data
  33. * @param integer $code Exception numerical code, if applicable
  34. */
  35. public function __construct($message, $type, $data = null, $code = 0) {
  36. parent::__construct($message, $code);
  37. $this->type = $type;
  38. $this->data = $data;
  39. }
  40. /**
  41. * Like {@see \Exception::getCode()}, but a string code.
  42. *
  43. * @codeCoverageIgnore
  44. * @return string
  45. */
  46. public function getType() {
  47. return $this->type;
  48. }
  49. /**
  50. * Gives any relevant data
  51. *
  52. * @codeCoverageIgnore
  53. * @return mixed
  54. */
  55. public function getData() {
  56. return $this->data;
  57. }
  58. }