Requests_Response::throw_for_status() WordPress Method

Requests_Response::throw_for_status() is a method of the Requests_Response class that throws an exception if the response has an HTTP status code that is not in the 2xx range. This method is useful for making sure that a response from a server is valid before further processing is done on it.

Requests_Response::throw_for_status( boolean $allow_redirects = true ) #

Throws an exception if the request was not successful


Parameters

$allow_redirects

(boolean)(Optional)Set to false to throw on a 3xx as well

Default value: true


Top ↑

Source

File: wp-includes/Requests/Response.php

	public function throw_for_status($allow_redirects = true) {
		if ($this->is_redirect()) {
			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);
		}
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.