Search in sources :

Example 6 with CypherException

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());
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpRequestException(org.neo4j.ogm.drivers.http.request.HttpRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) CypherException(org.neo4j.ogm.exception.CypherException) IOException(java.io.IOException)

Example 7 with CypherException

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());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CypherException(org.neo4j.ogm.exception.CypherException)

Example 8 with CypherException

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();
    }
}
Also used : User(org.neo4j.ogm.domain.social.User) CypherException(org.neo4j.ogm.exception.CypherException) Test(org.junit.Test)

Aggregations

CypherException (org.neo4j.ogm.exception.CypherException)8 ClientException (org.neo4j.driver.exceptions.ClientException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 Test (org.junit.Test)1 Bookmark (org.neo4j.driver.Bookmark)1 Result (org.neo4j.driver.Result)1 DatabaseException (org.neo4j.driver.exceptions.DatabaseException)1 TransientException (org.neo4j.driver.exceptions.TransientException)1 InternalBookmark (org.neo4j.driver.internal.InternalBookmark)1 QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)1 User (org.neo4j.ogm.domain.social.User)1 GraphRowModelResponse (org.neo4j.ogm.drivers.bolt.response.GraphRowModelResponse)1 RowModelResponse (org.neo4j.ogm.drivers.bolt.response.RowModelResponse)1 BoltTransaction (org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction)1 HttpRequestException (org.neo4j.ogm.drivers.http.request.HttpRequestException)1 ConnectionException (org.neo4j.ogm.exception.ConnectionException)1