Requests_Exception_HTTP

Exception based on HTTP response.

Defined (1)

The class is defined in the following location(s).

/wp-includes/Requests/Exception/HTTP.php  
  1. class Requests_Exception_HTTP extends Requests_Exception { 
  2. /** 
  3. * HTTP status code 
  4. * @var integer 
  5. */ 
  6. protected $code = 0; 
  7.  
  8. /** 
  9. * Reason phrase 
  10. * @var string 
  11. */ 
  12. protected $reason = 'Unknown'; 
  13.  
  14. /** 
  15. * Create a new exception 
  16. * There is no mechanism to pass in the status code, as this is set by the 
  17. * subclass used. Reason phrases can vary, however. 
  18. * @param string|null $reason Reason phrase 
  19. * @param mixed $data Associated data 
  20. */ 
  21. public function __construct($reason = null, $data = null) { 
  22. if ($reason !== null) { 
  23. $this->reason = $reason; 
  24.  
  25. $message = sprintf('%d %s', $this->code, $this->reason); 
  26. parent::__construct($message, 'httpresponse', $data, $this->code); 
  27.  
  28. /** 
  29. * Get the status message 
  30. */ 
  31. public function getReason() { 
  32. return $this->reason; 
  33.  
  34. /** 
  35. * Get the correct exception class for a given error code 
  36. * @param int|bool $code HTTP status code, or false if unavailable 
  37. * @return string Exception class name to use 
  38. */ 
  39. public static function get_class($code) { 
  40. if (!$code) { 
  41. return 'Requests_Exception_HTTP_Unknown'; 
  42.  
  43. $class = sprintf('Requests_Exception_HTTP_%d', $code); 
  44. if (class_exists($class)) { 
  45. return $class; 
  46.  
  47. return 'Requests_Exception_HTTP_Unknown';