Done !
| Server IP : 46.105.57.169 / Your IP : 216.73.216.67 Web Server : Apache System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : verseaumee ( 152031) PHP Version : 8.5.7 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/verseaumee/blueversion/wp-content/plugins/wpforms/src/Integrations/AI/API/Http/ |
Upload File : |
<?php
namespace WPForms\Integrations\AI\API\Http;
/**
* Response class.
*
* @since 1.9.1
*/
class Response {
/**
* Response.
*
* @since 1.9.1
*
* @var array
*/
protected $response;
/**
* Response constructor.
*
* @since 1.9.1
*
* @param array|\WP_Error $response Response.
*/
public function __construct( $response ) {
$this->response = $response;
}
/**
* Retrieve only the body from the raw response.
*
* @since 1.9.1
*
* @return array The body of the response.
*/
public function get_body(): array {
$body = wp_remote_retrieve_body( $this->response );
if ( empty( $body ) ) {
return [];
}
return json_decode( $body, true ) ?? [];
}
/**
* Get error data.
*
* @since 1.9.1
*
* @return array
*/
public function get_error_data(): array {
$code = $this->get_response_code();
return [
'error' => $this->get_response_message(),
'code' => empty( $code ) ? 'wp_error' : $code,
];
}
/**
* Retrieve only the response message from the raw response.
*
* @since 1.9.1
*
* @return string The response error.
*/
public function get_response_message(): string {
if ( is_wp_error( $this->response ) ) {
if ( $this->response->get_error_code() === 'http_request_failed' ) {
return __( 'There appears to be a network error.', 'wpforms-lite' );
}
return $this->response->get_error_message();
}
$body = $this->get_body();
return $body['error_message'] ?? wp_remote_retrieve_response_message( $this->response );
}
/**
* Retrieve only the response code from the raw response.
*
* @since 1.9.1
*
* @return int The response code as an integer.
*/
private function get_response_code(): int {
return absint( wp_remote_retrieve_response_code( $this->response ) );
}
/**
* Whether we received errors in the response.
*
* @since 1.9.1
*
* @return bool True if response has errors.
*/
public function has_errors(): bool {
$code = $this->get_response_code();
return $code < 200 || $code > 299;
}
}