Inheritance: extends Exception, implements GraphAware\Neo4j\Client\Exception\Neo4jExceptionInterface
 /**
  * Formats the Neo4j Response.
  *
  * @param array                                 $response
  * @param \GraphAware\Common\Cypher\Statement[] $statements
  *
  * @return ResultCollection
  *
  * @throws Neo4jException
  */
 public function format(array $response, array $statements)
 {
     if (isset($response['errors'][0])) {
         $e = new Neo4jException($response['errors'][0]['message']);
         $e->setNeo4jStatusCode($response['errors'][0]['code']);
         throw $e;
     }
     $results = new ResultCollection();
     foreach ($response['results'] as $k => $result) {
         $resultO = new Result($statements[$k]);
         $resultO->setFields($result['columns']);
         foreach ($result['data'] as $data) {
             $resultO->pushRecord($data['rest'], $data['graph']);
         }
         if (array_key_exists('stats', $result)) {
             $resultO->setStats($result['stats']);
         }
         $results->add($resultO, $statements[$k]->getTag());
     }
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * @param string      $statement
  * @param array|null  $parameters
  * @param null|string $tag
  *
  * @return \GraphAware\Common\Result\Result
  *
  * @throws Neo4jException
  */
 public function run($statement, $parameters = null, $tag = null)
 {
     $this->checkSession();
     $parameters = (array) $parameters;
     try {
         return $this->session->run($statement, $parameters, $tag);
     } catch (MessageFailureException $e) {
         $exception = new Neo4jException($e->getMessage());
         $exception->setNeo4jStatusCode($e->getStatusCode());
         throw $exception;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param int $transactionId
  *
  * @throws Neo4jException
  */
 public function rollbackTransaction($transactionId)
 {
     $request = new Request('DELETE', sprintf('%s/db/data/transaction/%d', $this->uri, $transactionId));
     try {
         $this->httpClient->send($request);
     } catch (RequestException $e) {
         if ($e->hasResponse()) {
             $body = json_decode($e->getResponse()->getBody(), true);
             if (!isset($body['code'])) {
                 throw $e;
             }
             $msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $body['errors'][0]['code'], $body['errors'][0]['message']);
             $exception = new Neo4jException($msg);
             $exception->setNeo4jStatusCode($body['errors'][0]['code']);
             throw $exception;
         }
         throw $e;
     }
 }