/** * Extract an error message from an exception thrown by Elastica. * @param RuntimeException $exception exception from which to extract a message * @return string message from the exception */ public static function extractMessage($exception) { if (!$exception instanceof ResponseException) { return $exception->getMessage(); } if ($exception instanceof PartialShardFailureException) { $shardStats = $exception->getResponse()->getShardsStatistics(); $message = array(); foreach ($shardStats['failures'] as $failure) { $message[] = $failure['reason']; } return 'Partial failure: ' . implode(',', $message); } return $exception->getElasticsearchException()->getMessage(); }