Esempio n. 1
0
 /**
  * Throws an exception if the request was not successful
  *
  * @throws Requests_Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
  * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404})
  * @param boolean $allow_redirects Set to false to throw on a 3xx as well
  */
 public function throw_for_status($allow_redirects = true)
 {
     if ($this->status_code >= 300 && $this->status_code < 400) {
         if (!$allow_redirects) {
             throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
         }
     } elseif (!$this->success) {
         $exception = Requests_Exception_HTTP::get_class($this->status_code);
         throw new $exception(null, $this);
     }
 }