3 * Exception based on HTTP response
9 * Exception based on HTTP response
13 class Requests_Exception_HTTP extends Requests_Exception {
26 protected $reason = 'Unknown';
29 * Create a new exception
31 * There is no mechanism to pass in the status code, as this is set by the
32 * subclass used. Reason phrases can vary, however.
34 * @param string|null $reason Reason phrase
35 * @param mixed $data Associated data
37 public function __construct($reason = null, $data = null) {
38 if ($reason !== null) {
39 $this->reason = $reason;
42 $message = sprintf('%d %s', $this->code, $this->reason);
43 parent::__construct($message, 'httpresponse', $data, $this->code);
47 * Get the status message
49 public function getReason() {
54 * Get the correct exception class for a given error code
56 * @param int|bool $code HTTP status code, or false if unavailable
57 * @return string Exception class name to use
59 public static function get_class($code) {
61 return 'Requests_Exception_HTTP_Unknown';
64 $class = sprintf('Requests_Exception_HTTP_%d', $code);
65 if (class_exists($class)) {
69 return 'Requests_Exception_HTTP_Unknown';