Handling errors

The result of any request against the transaction endpoint is streamed back to the client. Therefore, the server does not know whether the request will be successful or not when it sends the HTTP status code.

Because of this, all requests against the transactional endpoint will return 200 or 201 status code, regardless of whether statements were successfully executed. At the end of the response payload, the server includes a list of errors that occurred while executing statements. If the list is empty, the request completed successfully.

If errors occur while executing statements, the server will roll back the transaction.

In this example, we send an invalid statement to the server in order to demonstrate error handling.

For more information on the status codes, see Neo4j Status Codes.

Example request

  • POST http://localhost:7474/db/neo4j/tx/17/commit

  • Accept: application/json;charset=UTF-8

  • Content-Type: application/json

{
  "statements": [
    {
      "statement": "This is not a valid Cypher Statement."
    }
  ]
}

Example response

  • 200: OK

  • Content-Type: application/json;charset=utf-8

{
  "results" : [ ],
  "errors" : [ {
    "code" : "Neo.ClientError.Statement.SyntaxError",
    "message" : "Invalid input 'T': expected <init> (line 1, column 1 (offset: 0))\n\"This is not a valid Cypher Statement.\"\n ^"
  } ],
  "commit" : "http://localhost:7474/db/neo4j/tx/17/commit"
}