Skip to content

Commit

Permalink
accept response codes 200, 201 and 202
Browse files Browse the repository at this point in the history
  • Loading branch information
keski committed Sep 25, 2024
1 parent 84fcfa7 commit 9070efd
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Set;
import java.util.Base64;

public class Neo4jConnectionFactory
Expand Down Expand Up @@ -91,8 +92,13 @@ public List<TableRecord> execute( final String cypherQuery ) throws Neo4jExcepti
throw new Neo4jConnectionException(this, "Neo4j server could not be reached.", e);
}

System.err.println("Code: " + response.statusCode());
if ( ! ( response.statusCode() >= 200 && response.statusCode() < 300 ) ) {
// According to the Neo4J API documentation, a query can return 200 OK or 201
// Created when executed over the HTTP API because it wraps the request in an
// implicit transaction (i.e., the 201 can indicate that the transaction was
// successfully created, not that data was inserted/changed). It also lists 202
// Accepted as a possible response code in some circumstances. See
// https://neo4j.com/docs/query-api/current/query/
if ( ! (Set.of( 200, 201, 202 ).contains( response.statusCode() )) ) {
throw new Neo4jConnectionException(this, "Unexpected status code in HTTP response from Neo4j server: " + response.statusCode());
}

Expand Down

0 comments on commit 9070efd

Please sign in to comment.