Yoast\WP\SEO\AI\HTTP_Request\Application
Response_Validator::assert_success
Returns the response on success (HTTP 200); throws the matching typed exception otherwise.
Метод класса: Response_Validator{}
Хуков нет.
Возвращает
Response. The same response, on HTTP 200.
Использование
$Response_Validator = new Response_Validator(); $Response_Validator->assert_success( $response ): Response;
- $response(Response) (обязательный)
- The parsed response.
Код Response_Validator::assert_success() Response Validator::assert success Yoast 28.9
public function assert_success( Response $response ): Response {
$headers = $response->get_headers();
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception data is internal, not output.
switch ( $response->get_response_code() ) {
case 200:
return $response;
case 401:
throw new Unauthorized_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
case 402:
throw new Payment_Required_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $response->get_missing_licenses(), $headers );
case 403:
throw new Forbidden_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
case 404:
throw new Not_Found_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
case 408:
throw new Request_Timeout_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
case 429:
throw new Too_Many_Requests_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $response->get_missing_licenses(), $headers );
case 500:
throw new Internal_Server_Error_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
case 503:
throw new Service_Unavailable_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
default:
throw new Bad_Request_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $headers );
}
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
}