/** * Render and return a human readable error message for the given error document * * @return string * * @todo Parse Elasticsearch 2.x structured errors */ public function renderErrorMessage(RestApiResponse $response) { try { $errorDocument = $response->json(); } catch (IcingaException $e) { return sprintf('%s: %s', $e->getMessage(), $response->getPayload()); } if (!isset($errorDocument['error'])) { return sprintf('Elasticsearch unknown json error %s: %s', $response->getStatusCode(), $response->getPayload()); } if (is_string($errorDocument['error'])) { return $errorDocument['error']; } return sprintf('Elasticsearch json error %s: %s', $response->getStatusCode(), json_encode($errorDocument['error'])); }