On this page
Requests_Response::throw_for_status( boolean $allow_redirects = true )
Throws an exception if the request was not successful
Parameters
$allow_redirectsboolean Optional-
Set to false to throw on a 3xx as well
Default:
true
Source
File: wp-includes/Requests/Response.php. View all references
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);
}
}
Related
Uses
| Uses | Description |
|---|---|
| Requests_Exception_HTTP::get_class() wp-includes/Requests/Exception/HTTP.php | Get the correct exception class for a given error code |
| Requests_Response::is_redirect() wp-includes/Requests/Response.php | Is the response a redirect? |
| Requests_Exception::__construct() wp-includes/Requests/Exception.php | Create a new exception |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/requests_response/throw_for_status