EP_API::parse_api_response PHP Method

parse_api_response() public method

Determines if there is an issue or if the response is valid.
Since: 1.9
public parse_api_response ( object $response ) : array
$response object JSON decoded response from Elasticsearch.
return array Contains the status message or the returned statistics.
    public function parse_api_response($response)
    {
        if (null === $response) {
            return array('status' => false, 'msg' => esc_html__('Invalid response from ElasticPress server. Please contact your administrator.'));
        } elseif (isset($response->error) && (is_string($response->error) && stristr($response->error, 'IndexMissingException') || isset($response->error->reason) && stristr($response->error->reason, 'no such index'))) {
            if (is_multisite()) {
                $error = __('Site not indexed. <p>Please run: <code>wp elasticpress index --setup --network-wide</code> using WP-CLI. Or use the index button on the left of this screen.</p>', 'elasticpress');
            } else {
                $error = __('Site not indexed. <p>Please run: <code>wp elasticpress index --setup</code> using WP-CLI. Or use the index button on the left of this screen.</p>', 'elasticpress');
            }
            return array('status' => false, 'msg' => $error);
        }
        return array('status' => true, 'data' => $response->_all->primaries->indexing);
    }