public function flush(Pipeline $pipeline)
{
$request = $this->prepareRequest($pipeline);
try {
$response = $this->httpClient->send($request);
$data = json_decode((string) $response->getBody(), true);
if (!empty($data['errors'])) {
$msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $data['errors'][0]['code'], $data['errors'][0]['message']);
$exception = new Neo4jException($msg);
$exception->setNeo4jStatusCode($data['errors'][0]['code']);
throw $exception;
}
$results = $this->responseFormatter->format(json_decode($response->getBody(), true), $pipeline->statements());
return $results;
} 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;
}
}