use of org.neo4j.ogm.exception.CypherException in project neo4j-ogm by neo4j.
the class HttpDriver method executeHttpRequest.
public CloseableHttpResponse executeHttpRequest(HttpRequestBase request) throws HttpRequestException {
try (CloseableHttpResponse response = HttpRequest.execute(httpClient(), request, configuration.getCredentials())) {
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
JsonNode responseNode = mapper.readTree(EntityUtils.toString(responseEntity));
LOGGER.debug("Response: {}", responseNode);
JsonNode errors = responseNode.findValue("errors");
if (errors.elements().hasNext()) {
JsonNode errorNode = errors.elements().next();
throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText());
}
}
return response;
} catch (IOException ioe) {
throw new HttpRequestException(request, ioe);
} finally {
request.releaseConnection();
LOGGER.debug("Thread: {}, Connection released", Thread.currentThread().getId());
}
}
use of org.neo4j.ogm.exception.CypherException in project neo4j-ogm by neo4j.
the class AbstractHttpResponse method throwExceptionOnErrorEntry.
private void throwExceptionOnErrorEntry(JsonParser pointingToErrors) throws IOException {
if (pointingToErrors == null) {
return;
}
JsonNode errorsNode = mapper.readTree(pointingToErrors);
Optional<JsonNode> optionalErrorNode = StreamSupport.stream(errorsNode.spliterator(), false).findFirst();
if (optionalErrorNode.isPresent()) {
JsonNode errorNode = optionalErrorNode.get();
throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText());
}
}
use of org.neo4j.ogm.exception.CypherException in project neo4j-ogm by neo4j.
the class BasicDriverTest method shouldWrapUnderlyingException.
// GH-119
@Test
public void shouldWrapUnderlyingException() {
session.save(new User("Bilbo Baggins"));
try {
session.query(User.class, "MATCH(u:User) WHERE u.name ~ '.*Baggins' RETURN u", Collections.emptyMap());
fail("Expected a CypherException but got none");
} catch (CypherException ce) {
assertThat(ce.getCode().contains("Neo.ClientError.Statement")).isTrue();
}
}
Aggregations